Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
Some corrections in docs, fix typos, drop unused code.
  • Loading branch information
odersky committed Nov 26, 2024
1 parent 599d51c commit 83e0372
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ class Definitions {
def IArrayModuleClass: Symbol = IArrayModule.moduleClass

@tu lazy val ExpressibleAsCollectionLiteralClass: ClassSymbol = requiredClass("scala.compiletime.ExpressibleAsCollectionLiteral")
@tu lazy val ExpressibleACL_fromLiteral: Symbol = ExpressibleAsCollectionLiteralClass.requiredMethod("fromLiteral")

@tu lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
def UnitClass(using Context): ClassSymbol = UnitType.symbol.asClass
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4912,7 +4912,7 @@ object Types extends TypeUtils {
/** The state owning the variable. This is at first `creatorState`, but it can
* be changed to an enclosing state on a commit.
*/
private[dotc] var owningState: WeakReference[TyperState] | Null =
private[core] var owningState: WeakReference[TyperState] | Null =
if (creatorState == null) null else new WeakReference(creatorState)

/** The nesting level of this type variable in the current typer state. This is usually
Expand Down
13 changes: 10 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,10 @@ object Implicits:
extends SearchResult with RefAndLevel with Showable:
final def found = ref :: Nil

def isAmbiguousGiven(tree: Tree) = tree.tpe.isInstanceOf[AmbiguousImplicits | TooUnspecific]

/** A failed search */
case class SearchFailure(tree: Tree) extends SearchResult {
require(tree.tpe.isInstanceOf[SearchFailureType], s"unexpected type for ${tree}")
final def isAmbiguous: Boolean = isAmbiguousGiven(tree)
final def isAmbiguous: Boolean = tree.tpe.isInstanceOf[AmbiguousImplicits | TooUnspecific]
final def reason: SearchFailureType = tree.tpe.asInstanceOf[SearchFailureType]
final def found = tree.tpe match
case tpe: AmbiguousImplicits => tpe.alt1.ref :: tpe.alt2.ref :: Nil
Expand Down Expand Up @@ -622,6 +620,15 @@ object Implicits:
private def isUnderSpecifiedArgument(tp: Type)(using Context): Boolean =
tp.isRef(defn.NothingClass) || tp.isRef(defn.NullClass) || (tp eq NoPrefix)

/** Is `tp` not specific enough to warrant an implicit search for it?
* This is the case for
* - `?`, `Any`, `AnyRef`,
* - conversions from a bottom type, or to an underspecified type, or to `Unit
* - bounded wildcard types with underspecified upper bound
* The method is usually called after transforming a type with `wildApprox`,
* which means that type variables with underspecified upper constraints are also
* underspecified.
*/
def isUnderspecified(tp: Type)(using Context): Boolean = tp.stripTypeVar match
case tp: WildcardType =>
!tp.optBounds.exists || isUnderspecified(tp.optBounds.hiBound)
Expand Down
7 changes: 2 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,10 @@ object Inferencing {
* The method is called to instantiate type variables before an implicit search.
*/
def instantiateSelected(tp: Type, tvars: List[Type])(using Context): Unit =
if tvars.nonEmpty then instantiateSelected(tp, tvars.contains, minimize = true)

def instantiateSelected(tp: Type, cond: TypeVar => Boolean, minimize: Boolean)(using Context): Unit =
IsFullyDefinedAccumulator(
new ForceDegree.Value(IfBottom.flip):
override def appliesTo(tvar: TypeVar) = cond(tvar),
minimizeSelected = minimize
override def appliesTo(tvar: TypeVar) = tvars.contains(tvar),
minimizeSelected = true
).process(tp)

/** Instantiate any type variables in `tp` whose bounds contain a reference to
Expand Down
10 changes: 3 additions & 7 deletions docs/_docs/reference/experimental/collection-literals.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,9 @@ Using this scheme, the literals we have seen earlier could also be given alterna
- Since the fromLiteral method in `ExpressibleAsCollectionLiteral` is an inline method with inline arguments, given instances can implement it as a macro.

- The precise meaning of "is there an expected type?" is as follows: There is no expected
type if the expected type known from the context is _underdefined_ as specified for
implicit search. That is, implicit search for a conversion to the expected type would fail with an error message that contains a note like this:
```
Note that implicit conversions were not tried because the result of an implicit conversion|must be more specific than ...
```
Concretely, this is the case for Wildcard types `?`, `Any`, `AnyRef`, or type variables
bounded by one of these types.
type if the expected type known from the context is _under-specified_, as it is defined for
implicit search. That is, an implicit search for a given of the type would not be
attempted because the type is not specific enough. Concretely, this is the case for Wildcard types `?`, `Any`, `AnyRef`, unconstrained type variables, or type variables constrained from above by an under-specified type.

**Syntax**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import reflect.ClassTag
@experimental object ExpressibleAsCollectionLiteral:

// Some instances for standard collections. It would be good to have a method
// that works for all collections in stdlib. But to do that I believe we either
// have to put a given instance in Factory in stdlib, or write some macro
// method here. I have not found a straightforward way to build a collection
// of type `C` is all we know is the type.
// that works for all collections in stdlib. But to do that int his file,
// we have to write some macro method here. I have not found a straightforward
// way to build a collection of type `C` if all we know is the type.
// Once we can put Scala 3 code in the standard library this would be resolved by
// adding a given instance in Factory.

given seqFromLiteral: [T] => ExpressibleAsCollectionLiteral[collection.Seq[T]]:
type Elem = T
Expand Down

0 comments on commit 83e0372

Please sign in to comment.