Skip to content

Implement unused (renamed to ghost terms) #3342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4b81aae
Implement unused values
nicolasstucki Oct 3, 2017
ea4c483
Transform unused arguments to dummy values in typer
nicolasstucki Nov 16, 2017
cf52f93
Re-enable unused vals and defs
nicolasstucki Nov 16, 2017
85f9a70
Move NoInit checks to Mixin
nicolasstucki Dec 11, 2017
5e774d7
Add modifier to NonEmptyFunction and replace ImplicitFunction
nicolasstucki Dec 11, 2017
68ea63c
Document UnusedFunctionN and UnusedImplicitFunctionN
nicolasstucki Dec 11, 2017
7474ba3
Reformat code of UnusedFunctions in NameOpts
nicolasstucki Dec 11, 2017
e755dd8
Remove unnecessary early removal of unused prameters
nicolasstucki Dec 12, 2017
2177da5
Move error for unused case accessors
nicolasstucki Dec 12, 2017
724bf9c
Improve error message
nicolasstucki Dec 12, 2017
f1aa9fc
Remove unnecessary removal of unused accessors
nicolasstucki Dec 12, 2017
ae8f80e
Remove Nothing restriction on unused parameters
nicolasstucki Dec 12, 2017
81ec565
Change error message
nicolasstucki Dec 12, 2017
dd661dd
Remove special case for unused closure
nicolasstucki Dec 12, 2017
6a40b84
Keep stable unused arguments
nicolasstucki Dec 12, 2017
aa53182
Add documentation
nicolasstucki Dec 12, 2017
aba82ba
Complete doc of FunArgMods
nicolasstucki Dec 13, 2017
7c4662d
Use set for funArgMods
nicolasstucki Dec 13, 2017
ce2d805
Add missing syntax for FunArgMods
nicolasstucki Dec 13, 2017
544c8d5
Improve variable names
nicolasstucki Dec 13, 2017
f10f2d0
Improve comment
nicolasstucki Dec 13, 2017
ddf5b2c
Fix synthetic methods of value class with unused params
nicolasstucki Dec 14, 2017
7f81bc3
Make Unused flag a term flag only
nicolasstucki Dec 14, 2017
c877473
Add rules
nicolasstucki Jan 12, 2018
ed50958
Fix documentation
nicolasstucki Jan 23, 2018
c040798
Move methods from UnusedUtil to Applications
nicolasstucki Jan 23, 2018
68afbcd
Update unused parameter doc
nicolasstucki Feb 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1724,8 +1724,7 @@ object Parsers {
normalize(loop(start))
}

/** FunArgMods ::= `implicit' FunArgMods
* | `unused' FunArgMods
/** FunArgMods ::= { `implicit` | `unused` }
*/
def funArgMods = BitSet(IMPLICIT, UNUSED)

Expand Down
3 changes: 1 addition & 2 deletions docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ ClassQualifier ::= ‘[’ id ‘]’
Type ::= [FunArgMods] FunArgTypes ‘=>’ Type Function(ts, t)
| HkTypeParamClause ‘=>’ Type TypeLambda(ps, t)
| InfixType
FunArgMods ::= `implicit' FunArgMods
| `unused' FunArgMods
FunArgMods ::= { `implicit` | `unused` }
FunArgTypes ::= InfixType
| ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’
| '(' TypedFunParam {',' TypedFunParam } ')'
Expand Down
8 changes: 3 additions & 5 deletions docs/docs/reference/unused-terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ m.turnedOn.turnedOn // ERROR

Note that in the code above the actual implicit arguments for `IsOff` are never used at runtime; they serve only to establish the right constraints at compile time.
As these parameters are never used at runtime there is not real need to have them around, but they still need to be
present at runtime to be able to do separate compilation and retain binary compatiblity. Unused parameters are contractually
obligated to not be used at runtime, enforcing the essence of evidences on types and allows them to always be optimized away.

present at runtime to be able to do separate compilation and retain binary compatiblity.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

present at runtime --> present in some form in the generated code


How to define unused parameter?
-------------------------------
Expand All @@ -49,7 +47,7 @@ val lambdaWithUnusedEv: unused Ev => Int =
unused (ev: Ev) => 42
```

Those parameters will not be usable for computations, thought they can be used as arguments to other `unused` parameters.
`unused` parameters will not be usable for computations, though they can be used as arguments to other `unused` parameters.

```scala
def methodWithUnusedInt1(unused i: Int): Int =
Expand Down Expand Up @@ -84,7 +82,7 @@ methodWithUnusedEv(evidence1)

State machine with unused evidence example
------------------------------------------
The following examples is an extended implementation of a simple state machine which can be in a state `On` or `Off`.
The following example is an extended implementation of a simple state machine which can be in a state `On` or `Off`.
The machine can change state from `Off` to `On` with `turnedOn` only if it is currently `Off`,
conversely from `On` to `Off` with `turnedOff` only if it is currently `On`. These last constraint are
captured with the `IsOff[S]` and `IsOn[S]` implicit evidence only exist for `IsOff[Off]` and `InOn[On]`.
Expand Down