Commit Graph

25 Commits

Author SHA1 Message Date
Doug Gregor
ed6dccf12c Diagnose captured of non-sendable metatypes crossing isolation boundaries
Keep track of all of the type parameters and archetypes that are captured
by a local function or closure. Use that information to diagnose cases
where a non-Sendable metatype crosses an isolation boundary.
2025-02-13 17:07:09 -08:00
Michael Gottesman
791d07d379 Revert "Test fixes"
This reverts commit 9c328a81d1.
2025-02-06 14:04:28 -08:00
Tony Allevato
c5f0200680 Merge pull request #79059 from allevato/json-ast-followups
[ASTDumper] Some followups from the initial JSON PR and macro dumping improvements.
2025-02-04 01:13:46 -05:00
Michael Gottesman
9c328a81d1 Test fixes 2025-02-03 13:35:08 -08:00
Tony Allevato
5fe10ce86a ASTDumper: Label "interface type" -> "interface_type". 2025-01-29 13:55:00 -05:00
Sophia Poirier
5ce7be7e75 [Concurrency] explicit nonisolated specification for closures 2024-03-14 12:24:13 -07:00
Becca Royal-Gordon
8770c7f826 Rework ASTDumper (#68438)
This PR refactors the ASTDumper to make it more structured, less mistake-prone, and more amenable to future changes. For example:

```cpp
  // Before:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E) {
    printCommon(E, "unresolved_dot_expr")
      << " field '" << E->getName() << "'";
    PrintWithColorRAII(OS, ExprModifierColor)
      << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind());
    if (E->getBase()) {
      OS << '\n';
      printRec(E->getBase());
    }
    PrintWithColorRAII(OS, ParenthesisColor) << ')';
  }

  // After:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E, StringRef label) {
    printCommon(E, "unresolved_dot_expr", label);

    printFieldQuoted(E->getName(), "field");
    printField(E->getFunctionRefKind(), "function_ref", ExprModifierColor);

    if (E->getBase()) {
      printRec(E->getBase());
    }

    printFoot();
  }
```

* Values are printed through calls to base class methods, rather than direct access to the underlying `raw_ostream`.
    * These methods tend to reduce the chances of bugs like missing/extra spaces or newlines, too much/too little indentation, etc.
    * More values are quoted, and unprintable/non-ASCII characters in quoted values are escaped before printing.
* Infrastructure to label child nodes now exists.
    * Some weird breaks from the normal "style", like `PatternBindingDecl`'s original and processed initializers, have been brought into line.
* Some types that previously used ad-hoc dumping functions, like conformances and substitution maps, are now structured similarly to the dumper classes.
* I've fixed the odd dumping bug along the way. For example, distributed actors were only marked `actor`, not `distributed actor`.

This PR doesn't change the overall style of AST dumps; they're still pseudo-S-expressions. But the logic that implements this style is now isolated into a relatively small base class, making it feasible to introduce e.g. JSON dumping in the future.
2023-09-11 23:56:38 -07:00
Slava Pestov
0ade7b70d9 AST: Type::subst() preserves TypeAliasType sugar
Fixes <rdar://problem/45313760>.
2019-09-24 17:42:15 -04:00
Vinicius Vendramini
39d3963131 Fix broken tests
- Many tests got broken because of two things:
  - AST dump now outputs to stdout, but many tests expected stderr. This was a straightforward fix.
  - Many tests call swift with specific parameters; specifically, many call `swift frontend` directly. This makes them go through the compiler in unexpected ways, and specifically it makes them not have primary files, which breaks the new AST dump implementation. This commit adds the old implementation as a fallback for those cases, except it dumps to `stdout` to maintain some consistence.

Finally, the `/test/Driver/filelists.swift` failed for unknown reasons. It seems its output now had some lines out of order, and fixing the order made the test pass. However, as the reasons why it failed are unknown, this fix might not have been a good idea. Corrections are welcome.
2018-11-14 13:38:01 -02:00
Davide Italiano
4fed893d74 [AST] Preserve sugar for generic typealiases.
<rdar://problem/43110802>
2018-09-17 15:34:37 -07:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Brent Royal-Gordon
fb79b8f44e Indicate which closures are escaping in AST dumps 2018-06-10 14:03:01 -07:00
Mark Rowe
62eb12b652 Include source ranges for decls in the AST dump. 2018-05-17 10:50:19 -07:00
Ben Langmuir
f20586b3d8 Revert "Include source ranges for statements, declarations, and parameter lists in the AST dump" 2018-05-17 09:53:05 -07:00
Mark Rowe
28af6959b8 Include source ranges for decls in the AST dump. 2018-05-09 11:15:35 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
Brian Gesiak
ff7f01c7e5 [AST] Missing space when printing generic params
Using `-dump-parse` on `func foo<T>(bar: T) {}` results in:

```
(source_file
  (func_decl "foo(bar:)"<T>
    (parameter_list
      (parameter "bar" apiName=bar))
    (brace_stmt)))
```

Notice there is no space between "foo(bar:)" and <T>.

Add a space to correct the formatting error.
2017-01-04 15:58:02 -05:00
Slava Pestov
2c6b9f71b6 AST: Change TypeAliasDecls to store an interface type as their underlying type
- TypeAliasDecl::getAliasType() is gone. Now, getDeclaredInterfaceType()
  always returns the NameAliasType.

- NameAliasTypes now always desugar to the underlying type as an
  interface type.

- The NameAliasType of a generic type alias no longer desugars to an
  UnboundGenericType; call TypeAliasDecl::getUnboundGenericType() if you
  want that.

- The "lazy mapTypeOutOfContext()" hack for deserialized TypeAliasDecls
  is gone.

- The process of constructing a synthesized TypeAliasDecl is much simpler
  now; instead of calling computeType(), setInterfaceType() and then
  setting the recursive properties in the right order, just call
  setUnderlyingType(), passing it either an interface type or a
  contextual type.

  In particular, many places weren't setting the recursive properties,
  such as the ClangImporter and deserialization. This meant that queries
  such as hasArchetype() or hasTypeParameter() would return incorrect
  results on NameAliasTypes, which caused various subtle problems.

- Finally, add some more tests for generic typealiases, most of which
  fail because they're still pretty broken.
2016-12-15 22:46:15 -08:00
Slava Pestov
c4dbf91676 AST Dumper: Don't canonicalize interface types 2016-12-01 13:00:19 -08:00
Slava Pestov
a1eef126ba AST: Don't print "aka <<desugared type>>" for generic function types
This was causing us to emit diagnostics talking about τ_m_n, which is
not helpful.

Now that generic function types print sanely, print them in a few
places where we were previously printing PolymorphicFunctionTypes.
2016-09-15 21:47:57 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Jordan Rose
f42158b12e Revert "[Sema] ban multi-arguments to tuple coercion" (#3922)
It breaks cases where there really is a single unlabeled argument of tuple type, like this:

  let pairs = [(1, "A"), (2, "B")]
  print(pairs.map { $0.0 })
2016-08-01 19:22:19 -07:00
Daniel Duan
c9b73dacc2 [Sema] ban multi-arguments to tuple coercion
Implements part of SE-0110. Single argument in closures will not be accepted if
there exists explicit type with a number of arguments that's not 1.

```swift
let f: (Int, Int) -> Void = { x in } // this is now an error
```

Note there's a second part of SE-0110 which could be considered additive,
which says one must add an extra pair of parens to specify a single arugment
type that is a tuple:

```swift
let g ((Int, Int)) -> Void = { y in } // y should have type (Int, Int)
```

This patch does not implement that part.
2016-07-31 16:22:57 -07:00
Slava Pestov
f8f6d61d19 Fixes for typealiases involving generics (#3811)
* Serialization: Another fix for generic typealiases

Fixes <https://bugs.swift.org/browse/SR-1889>.

* Sema: Fix FindCapturedVars to look through typealiases

Fixes <https://bugs.swift.org/browse/SR-1781>.
2016-07-27 21:35:37 -07:00
Slava Pestov
c870052520 Sema: Give capture analysis ability to sniff out uses of dynamic 'Self'
This also adds some tests for the existing generic parameter
capture logic, which was only tested as part of SILGen tests
until now.

Also, move capture analysis into a new TypeCheckCaptures.cpp file.
2016-06-27 18:37:52 -07:00