Skip to content

Commit

Permalink
Rename implied to delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jun 9, 2019
1 parent ed8c6ee commit 950d874
Show file tree
Hide file tree
Showing 118 changed files with 678 additions and 672 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ object Flags {
/** Symbol is a Java default method */
final val DefaultMethod: FlagSet = termFlag(38, "<defaultmethod>")

final val Implied: FlagSet = commonFlag(39, "implied")
final val Implied: FlagSet = commonFlag(39, "delegate")

/** Symbol is an enum class or enum case (if used with case) */
final val Enum: FlagSet = commonFlag(40, "<enum>")
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object Completion {
if (buffer.mode != Mode.None) {
path match {
case Select(qual, _) :: _ => buffer.addMemberCompletions(qual)
case Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) // TODO: distinguish implied from non-implied
case Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) // TODO: distinguish delegate from non-delegate
case (_: Thicket) :: Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr)
case _ => buffer.addScopeCompletions
}
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ object Parsers {
* | SimpleExpr1 ArgumentExprs `=' Expr
* | Expr2
* | [‘inline’] Expr2 `match' `{' CaseClauses `}'
* | `implied' `match' `{' ImplicitCaseClauses `}'
* | `delegate' `match' `{' ImplicitCaseClauses `}'
* Bindings ::= `(' [Binding {`,' Binding}] `)'
* Binding ::= (id | `_') [`:' Type]
* Expr2 ::= PostfixExpr [Ascription]
Expand Down Expand Up @@ -1470,7 +1470,7 @@ object Parsers {
*/
def impliedMatch(start: Int, imods: Modifiers) = {
def markFirstIllegal(mods: List[Mod]) = mods match {
case mod :: _ => syntaxError(em"illegal modifier for implied match", mod.span)
case mod :: _ => syntaxError(em"illegal modifier for delegate match", mod.span)
case _ =>
}
imods.mods match {
Expand All @@ -1485,7 +1485,7 @@ object Parsers {
case pat => isVarPattern(pat)
}
if (!isImplicitPattern(pat))
syntaxError(em"not a legal pattern for an implied match", pat.span)
syntaxError(em"not a legal pattern for a delegate match", pat.span)
}
result
}
Expand Down Expand Up @@ -2351,8 +2351,8 @@ object Parsers {

type ImportConstr = (Boolean, Tree, List[Tree]) => Tree

/** Import ::= import [implied] [ImportExpr {`,' ImportExpr}
* Export ::= export [implied] [ImportExpr {`,' ImportExpr}
/** Import ::= import [delegate] [ImportExpr {`,' ImportExpr}
* Export ::= export [delegate] [ImportExpr {`,' ImportExpr}
*/
def importClause(leading: Token, mkTree: ImportConstr): List[Tree] = {
val offset = accept(leading)
Expand Down Expand Up @@ -2383,7 +2383,7 @@ object Parsers {
wildcardIdent() :: Nil
case FOR =>
if (!importImplied)
syntaxError(em"`for` qualifier only allowed in `import implied`")
syntaxError(em"`for` qualifier only allowed in `import delegate`")
atSpan(in.skipToken()) {
var t = infixType()
while (in.token == COMMA) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Tokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ object Tokens extends TokensCommon {
final val FORSOME = 61; enter(FORSOME, "forSome") // TODO: deprecate
final val ENUM = 62; enter(ENUM, "enum")
final val ERASED = 63; enter(ERASED, "erased")
final val IMPLIED = 64; enter(IMPLIED, "implied")
final val IMPLIED = 64; enter(IMPLIED, "delegate")
final val GIVEN = 65; enter(GIVEN, "given")
final val EXPORT = 66; enter(EXPORT, "export")
final val MACRO = 67; enter(MACRO, "macro") // TODO: remove
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case id :: Nil => toText(id)
case _ => "{" ~ Text(selectors map selectorText, ", ") ~ "}"
}
keywordText("import ") ~ (keywordText("implied ") provided importImplied) ~
keywordText("import ") ~ (keywordText("delegate ") provided importImplied) ~
toTextLocal(expr) ~ "." ~ selectorsText
case packageDef: PackageDef =>
packageDefText(packageDef)
Expand Down Expand Up @@ -815,7 +815,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
if (ctx.settings.YdebugFlags.value) AnyFlags
else if (suppressKw) PrintableFlags(isType) &~ Private
else PrintableFlags(isType)
if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= ImplicitOrImplied // drop implicit/implied from classes
if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= ImplicitOrImplied // drop implicit/delegate from classes
val rawFlags = if (sym.exists) sym.flags else mods.flags
if (rawFlags.is(Param)) flagMask = flagMask &~ Given
val flags = rawFlags & flagMask
Expand Down
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
*
* T => R <:s U => R
*
* Also: If a compared type refers to an implied object or its module class, use
* Also: If a compared type refers to an delegate or its module class, use
* the intersection of its parent classes instead.
*/
def isAsSpecificValueType(tp1: Type, tp2: Type)(implicit ctx: Context) =
Expand All @@ -1342,22 +1342,22 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
(prepare(tp1) relaxed_<:< prepare(tp2)) || viewExists(tp1, tp2)
}

/** Widen the result type of synthetic implied methods from the implementation class to the
/** Widen the result type of synthetic delegate methods from the implementation class to the
* type that's implemented. Example
*
* implied I[X] for T { ... }
* delegate I[X] for T { ... }
*
* This desugars to
*
* class I[X] extends T { ... }
* implied def I[X]: I[X] = new I[X]
* implicit def I[X]: I[X] = new I[X]
*
* To compare specificity we should compare with `T`, not with its implementation `I[X]`.
* No such widening is performed for implied aliases, which are not synthetic. E.g.
* No such widening is performed for delegate aliases, which are not synthetic. E.g.
*
* implied J[X] for T = rhs
* delegate J[X] for T = rhs
*
* already has the right result type `T`. Neither is widening performed for implied
* already has the right result type `T`. Neither is widening performed for delegate
* objects, since these are anyway taken to be more specific than methods
* (by condition 3a above).
*/
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ trait Implicits { self: Typer =>
case fail: SearchFailureType =>

def hiddenImplicitNote(s: SearchSuccess) =
em"\n\nNote: implied instance ${s.ref.symbol.showLocated} was not considered because it was not imported with an `import implied`."
em"\n\nNote: delegate ${s.ref.symbol.showLocated} was not considered because it was not imported with `import delegate`."

def FindHiddenImplicitsCtx(ctx: Context): Context =
if (ctx == NoContext) ctx
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ImportInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object ImportInfo {
* @param selectors The selector clauses
* @param symNameOpt Optionally, the name of the import symbol. None for root imports.
* Defined for all explicit imports from ident or select nodes.
* @param importImplied true if this is an implied import
* @param importImplied true if this is a delegate import
* @param isRootImport true if this is one of the implicit imports of scala, java.lang,
* scala.Predef or dotty.DottyPredef in the start context, false otherwise.
*/
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
/** Reduce an inline match
* @param mtch the match tree
* @param scrutinee the scrutinee expression, assumed to be pure, or
* EmptyTree for an implied match
* EmptyTree for a delegate match
* @param scrutType its fully defined type, or
* ImplicitScrutineeTypeRef for an implied match
* ImplicitScrutineeTypeRef for a delegate match
* @param typer The current inline typer
* @return optionally, if match can be reduced to a matching case: A pair of
* bindings for all pattern-bound variables and the RHS of the case.
Expand Down Expand Up @@ -1036,10 +1036,10 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
def patStr(cdef: untpd.CaseDef) = i"case ${cdef.pat}${guardStr(cdef.guard)}"
val msg =
if (tree.selector.isEmpty)
em"""cannot reduce implied match with
em"""cannot reduce delegate match with
| patterns : ${tree.cases.map(patStr).mkString("\n ")}"""
else
em"""cannot reduce inline match with
em"""cannot reduce delegate match with
| scrutinee: $sel : ${selType}
| patterns : ${tree.cases.map(patStr).mkString("\n ")}"""
errorTree(tree, msg)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ class Namer { typer: Typer =>

def whyNoForwarder(mbr: SingleDenotation): String = {
val sym = mbr.symbol
if (sym.is(ImplicitOrImpliedOrGiven) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}implied"
if (sym.is(ImplicitOrImpliedOrGiven) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}a delegate"
else if (!sym.isAccessibleFrom(path.tpe)) "is not accessible"
else if (sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge)) SKIP
else if (cls.derivesFrom(sym.owner) &&
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ class Typer extends Namer
tree.selector match {
case EmptyTree =>
if (tree.isInline) {
checkInInlineContext("implied match", tree.posd)
checkInInlineContext("delegate match", tree.posd)
val cases1 = tree.cases.mapconserve {
case cdef @ CaseDef(pat @ Typed(Ident(nme.WILDCARD), _), _, _) =>
// case _ : T --> case evidence$n : T
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/io/ZipArchive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
override def input: InputStream = {
val zipFile = openZipFile()
val entry = zipFile.getEntry(name)
val delegate = zipFile.getInputStream(entry)
new FilterInputStream(delegate) {
val `delegate` = zipFile.getInputStream(entry)
new FilterInputStream(`delegate`) {
override def close(): Unit = { zipFile.close() }
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ReplCompilerTests extends ReplTest {
}

@Test def i5897 =
fromInitialState { implicit state => run("implied for Int = 10") }
fromInitialState { implicit state => run("delegate for Int = 10") }
.andThen { implicit state =>
assertEquals(
"def Int_instance: Int",
Expand All @@ -151,7 +151,7 @@ class ReplCompilerTests extends ReplTest {
| def (x: T) > (y: T) = compare(x, y) > 0
|}
|
|implied IntOrd for Ord[Int] {
|delegate IntOrd for Ord[Int] {
| def compare(x: Int, y: Int) =
| if (x < y) -1 else if (x > y) +1 else 0
|}
Expand Down
30 changes: 14 additions & 16 deletions docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ semi ::= ‘;’ | nl {nl}
### Regular keywords

```
abstract case catch class def do else enum
erased extends false final finally for given if
implicit implied import lazy match new null object
abstract case catch class def delegate do else
enum export extends false final finally for given
if implicit import lazy match new null object
package private protected override return super sealed then
throw trait true try type val var while
with yield
Expand Down Expand Up @@ -143,7 +143,7 @@ Type ::= FunType
| HkTypeParamClause ‘=>>’ Type TypeLambda(ps, t)
| MatchType
| InfixType
FunType ::= { 'erased' | 'given' } (MonoFunType | PolyFunType)
FunType ::= ['given'] (MonoFunType | PolyFunType)
MonoFunType ::= FunArgTypes ‘=>’ Type Function(ts, t)
PolyFunType :: = HKTypeParamClause '=>' Type PolyFunction(ps, t)
FunArgTypes ::= InfixType
Expand Down Expand Up @@ -298,8 +298,8 @@ HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (Id[HkTypeParamClause] |
ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
| {ClsParamClause} {GivenClsParamClause}
ClsParamClause ::= [‘erased’] (‘(’ ClsParams ‘)’
GivenClsParamClause::= ‘given’ [‘erased’] (‘(’ ClsParams ‘)’ | GivenTypes)
ClsParamClause ::= ‘(’ ClsParams ‘)’
GivenClsParamClause::= ‘given’ (‘(’ ClsParams ‘)’ | GivenTypes)
ClsParams ::= ClsParam {‘,’ ClsParam}
ClsParam ::= {Annotation} ValDef(mods, id, tpe, expr) -- point of mods on val/var
[{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
Expand All @@ -308,12 +308,12 @@ Param ::= id ‘:’ ParamType [‘=’ Expr]
DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
| {DefParamClause} {GivenParamClause}
DefParamClause ::= [‘erased’] (‘(’ DefParams ‘)’
GivenParamClause ::= ‘given’ [‘erased’] (‘(’ DefParams ‘)’ | GivenTypes)
DefParamClause ::= ‘(’ DefParams ‘)’
GivenParamClause ::= ‘given’ (‘(’ DefParams ‘)’ | GivenTypes)
DefParams ::= DefParam {‘,’ DefParam}
DefParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id.
GivenTypes ::= AnnotType {‘,’ AnnotType}
ClosureMods ::= { ‘implicit’ | ‘erased’ | ‘given’}
ClosureMods ::= { ‘implicit’ | ‘given’}
```

### Bindings and Imports
Expand All @@ -331,20 +331,19 @@ LocalModifier ::= ‘abstract’
| ‘implicit’
| ‘lazy’
| ‘inline’
| ‘erased’
AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier]
AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’
Annotation ::= ‘@’ SimpleType {ParArgumentExprs} Apply(tpe, args)
Import ::= ‘import’ [‘implied’] ImportExpr {‘,’ ImportExpr}
Import ::= ‘import’ [‘delegate’] ImportExpr {‘,’ ImportExpr}
ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) Import(expr, sels)
ImportSelectors ::= ‘{’ {ImportSelector ‘,’} FinalSelector ‘}’
FinalSelector ::= ImportSelector Ident(name)
| ‘_’ Pair(id, id)
| ‘for’ InfixType {‘,’ InfixType} TypeBoundsTree(EmptyTree, tpt)
ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’]
Export ::= ‘export’ [‘implied’] ImportExpr {‘,’ ImportExpr}
Export ::= ‘export’ [‘delegate’] ImportExpr {‘,’ ImportExpr}
```

### Declarations and Definitions
Expand Down Expand Up @@ -380,16 +379,15 @@ DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
| [‘case’] ‘object’ ObjectDef
| ‘enum’ EnumDef
| ‘implied’ InstanceDef
| ‘delegate’ DelegateDef
| Export
ClassDef ::= id ClassConstr [Template] ClassDef(mods, name, tparams, templ)
ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses with DefDef(_, <init>, Nil, vparamss, EmptyTree, EmptyTree) as first stat
ConstrMods ::= {Annotation} [AccessModifier]
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
InstanceDef ::= [id] [DefTypeParamClause] InstanceBody
InstanceParams ::= [DefTypeParamClause] {GivenParamClause}
InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
DelegateDef ::= [id] [DefTypeParamClause] DelegateBody
DelegateBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
| ‘for’ Type {GivenParamClause} ‘=’ Expr
Template ::= InheritClauses [TemplateBody] Template(constr, parents, self, stats)
InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}]
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/reference/changed-features/implicit-resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ affect implicits on the language level.
Example:

package p
implied a for A
delegate a for A

object o {
implied b for B
delegate b for B
type C
}

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/reference/contextual/context-bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ title: "Context Bounds"

## Context Bounds

A context bound is a shorthand for expressing a common pattern of a context parameter that depends on a type parameter. Using a context bound, the `maximum` function of the last section can be written like this:
A context bound is a shorthand for expressing the common pattern of an implicit parameter that depends on a type parameter. Using a context bound, the `maximum` function of the last section can be written like this:
```scala
def maximum[T: Ord](xs: List[T]): T = xs.reduceLeft(max)
```
A bound like `: Ord` on a type parameter `T` of a method or class indicates a context parameter `given Ord[T]`. The context parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
A bound like `: Ord` on a type parameter `T` of a method or class indicates an implicit parameter `given Ord[T]`. The implicit parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
```scala
def f[T: C1 : C2, U: C3](x: T) given (y: U, z: V): R
```
Expand Down
Loading

0 comments on commit 950d874

Please sign in to comment.