Skip to content

Commit

Permalink
Automatic dereferencing is removed (nim-lang#20531)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored and capocasa committed Mar 31, 2023
1 parent 352098a commit 0cb6287
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 104 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
- Optional parameters in combination with `: body` syntax (RFC #405) are now opt-in via
`experimental:flexibleOptionalParams`.

- Automatic dereferencing (experimental feature) is removed.

- The `Math.trunc` polyfill for targeting Internet Explorer was
previously included in most JavaScript output files.
Now, it is only included with `-d:nimJsMathTruncPolyfill`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ type
ideRecompile, ideChanged, ideType, ideDeclaration

Feature* = enum ## experimental features; DO NOT RENAME THESE!
implicitDeref,
implicitDeref, # deadcode; remains here for backwards compatibility
dotOperators,
callOperator,
parallel,
Expand Down
21 changes: 0 additions & 21 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -580,27 +580,6 @@ proc semOverloadedCall(c: PContext, n, nOrig: PNode,
"Non-matching candidates for " & renderTree(n) & "\n" &
candidates)
result = semResolvedCall(c, r, n, flags)
elif implicitDeref in c.features and canDeref(n):
# try to deref the first argument and then try overloading resolution again:
#
# XXX: why is this here?
# it could be added to the long list of alternatives tried
# inside `resolveOverloads` or it could be moved all the way
# into sigmatch with hidden conversion produced there
#
n[1] = n[1].tryDeref
var r = resolveOverloads(c, n, nOrig, filter, flags, errors, efExplain in flags)
if r.state == csMatch: result = semResolvedCall(c, r, n, flags)
else:
# get rid of the deref again for a better error message:
n[1] = n[1][0]
#notFoundError(c, n, errors)
if efExplain notin flags:
# repeat the overload resolution,
# this time enabling all the diagnostic output (this should fail again)
discard semOverloadedCall(c, n, nOrig, filter, flags + {efExplain})
elif efNoUndeclared notin flags:
notFoundError(c, n, errors)
else:
if efExplain notin flags:
# repeat the overload resolution,
Expand Down
6 changes: 0 additions & 6 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,6 @@ proc resolveIndirectCall(c: PContext; n, nOrig: PNode;
t: PType): TCandidate =
initCandidate(c, result, t)
matches(c, n, nOrig, result)
if result.state != csMatch:
# try to deref the first argument:
if implicitDeref in c.features and canDeref(n):
n[1] = n[1].tryDeref
initCandidate(c, result, t)
matches(c, n, nOrig, result)

proc bracketedMacro(n: PNode): PSym =
if n.len >= 1 and n[0].kind == nkSym:
Expand Down
4 changes: 0 additions & 4 deletions doc/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1984,10 +1984,6 @@ dereferencing operations for reference types:
# no need to write n[].data; in fact n[].data is highly discouraged!
```

Automatic dereferencing can be performed for the first argument of a routine
call, but this is an experimental feature and is described [here](
manual_experimental.html#automatic-dereferencing).

In order to simplify structural type checking, recursive tuples are not valid:

```nim
Expand Down
23 changes: 0 additions & 23 deletions doc/manual_experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,29 +286,6 @@ scope. Therefore, the following will *fail to compile:*
This feature will likely be replaced with a better solution to remove
the need for forward declarations.


Automatic dereferencing
=======================

Automatic dereferencing is performed for the first argument of a routine call.
This feature has to be enabled via `{.experimental: "implicitDeref".}`:

```nim
{.experimental: "implicitDeref".}
type
NodeObj = object
# ...
Node = ref NodeObj
proc depth(x: NodeObj): int = ...
let n = Node()
echo n.depth
# no need to write n[].depth
```


Special Operators
=================

Expand Down
49 changes: 0 additions & 49 deletions tests/implicit/timplicit.nim

This file was deleted.

15 changes: 15 additions & 0 deletions tests/objects/tobject.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ block: # bug #14698
x1: int
x3: seq[int]
doAssert t[].sizeof == Foo1.sizeof

# bug #147
type
TValue* {.pure, final.} = object of RootObj
a: int
PValue = ref TValue
PPValue = ptr PValue


var x: PValue
new x
var sp: PPValue = addr x

sp.a = 2
doAssert sp.a == 2

0 comments on commit 0cb6287

Please sign in to comment.