Commit Graph

146 Commits

Author SHA1 Message Date
David Ungar
10583f89c6 Ensure that reexpansion does not lose scopes. 2019-09-22 17:59:40 -07:00
David Ungar
c808eb5a27 Don't try to expand ASTSourceFileScope when eagerly building. 2019-09-22 17:59:40 -07:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
David Ungar
3966d086a5 When ASTScope assertions fails, direct user to try disabling ASTScopes. 2019-09-17 15:56:33 -07:00
Sasha Krassovsky
1e414f7fb6 Fix warnings in AST 2019-09-13 09:57:48 -07:00
David Ungar
7992e1c6c4 Lots of cleanups, renamings, etc. 2019-08-26 16:55:18 -07:00
David Ungar
f64033a2d2 Manual rebase with master 2019-08-06 22:13:20 -07:00
David Ungar
3a3145c0f4 Alternate SelfDC computation, fixes, and cleanups.
ASTScopeLookup by default
Create empty fn bodies for IDE tests.
Include initializer source range for property wrappers.
Add -disable-astscope-lookup
2019-06-23 09:17:09 -07:00
David Ungar
455b344397 fmt 2019-06-10 15:38:01 -07:00
David Ungar
f203509250 fixes, unfmted, rm startLocAccordingToCondition 2019-06-10 14:03:34 -07:00
David Ungar
17bb03112e new cond use scheme 2019-06-10 13:18:18 -07:00
David Ungar
7d1f024e07 WIP unfmt 2019-06-10 12:10:21 -07:00
David Ungar
a724ff1446 undo lastAdopter transfer and rename, fix use expansion, rm depth 2019-06-09 09:57:32 -07:00
David Ungar
3abfa1f384 WIP 2019-06-08 09:08:49 -07:00
David Ungar
670eb61f8e Spell out GTX 2019-06-05 15:54:10 -07:00
David Ungar
05d38e0c53 Source range optimization 2019-06-05 14:15:47 -07:00
David Ungar
dd5d4ab492 Rm unused 2019-06-05 08:33:03 -07:00
David Ungar
1c0da7511c Renaming 2019-06-05 08:31:00 -07:00
David Ungar
23bddf12b4 Format 2019-05-31 21:03:05 -07:00
David Ungar
005e259247 compiles, unfmt 2019-05-31 21:02:19 -07:00
David Ungar
e6012a4809 fixes 2019-05-31 13:56:29 -07:00
David Ungar
2e7756c5c9 WP Redoing 2019-05-30 21:59:07 -07:00
David Ungar
10affe2b3b Cosmetic fixes. 2019-05-28 15:46:32 -07:00
David Ungar
3f820c374e Some review tweaks. 2019-05-28 11:12:12 -07:00
David Ungar
663760e3b7 ASTOOScope ontology 2019-05-28 10:48:22 -07:00
Slava Pestov
18dc8d4bd1 AST: Fix ASTScope lookup for invalid extensions
If there are no braces, the start and end location of the range is
the same token, so don't create a TypeOrExtensionBody scope at all.

NFC for now, but this problem causes some tests to fail once we
enable cycle diagnostics.
2019-04-22 22:22:23 -04:00
Joe Groff
71912bbfd6 AST: Represent OpaqueTypeDecls.
To represent the abstracted interface of an opaque type, we need a generic signature that refines
the outer context generic signature with an additional generic parameter representing the underlying
type and its exposed constraints. Opaque types also need to be keyed by their originating decl, so
that we can treat values of the same opaque type as the same. When we check a FuncDecl with an
opaque type specified as its return type, create an OpaqueTypeDecl and associate it with the
originating decl. (A representation for *types* derived from the opaque decl will come next.)
2019-04-17 14:43:32 -07:00
Marc Rasi
bf18697b4f parsing, typechecking, and SILGen for #assert
`#assert` is a new static assertion statement that will let us write
tests for the new constant evaluation infrastructure that we are working
on. `#assert` works by lowering to a `Builtin.poundAssert` SIL
instruction. The constant evaluation infrastructure will look for these
SIL instructions, const-evaluate their conditions, and emit errors if
the conditions are non-constant or false.

This commit implements parsing, typechecking and SILGen for `#assert`.
2018-11-07 16:34:17 -08:00
Doug Gregor
3018becde7 [Type checker] Eliminate type checking from early extension binding.
Use ExtensionDecl::getExtendedNominal() to wire up extensions to their
nominal types early in type checking (the bindExtensions()) operation,
rather than going through type validation to do so.
2018-08-03 11:26:49 -07:00
Doug Gregor
bd5f5d80e4 [AST] Add ExtensionDecl::getExtendedNominal().
Introduce ExtensionDecl::getExtendedNominal() to provide the nominal
type declaration that the extension declaration extends. Move most
of the existing callers of the callers to getExtendedType() over to
getExtendedNominal(), because they don’t need the full type information.

ExtensionDecl::getExtendedNominal() is itself not very interesting yet,
because it depends on getExtendedType().
2018-08-03 11:26:48 -07:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Slava Pestov
90cd772228 AST: Remove getParameterLists() and friends from AbstractFunctionDecl subclasses
Now, an AbstractFunctionDecl always stores a single parameter list.

Furthermore, ConstructorDecl and DestructorDecl always store a
ParamDecl for 'self'.

FuncDecl only has a 'self' if it is a member of a nominal type or
extension, so we tail-allocate the storage for it.
2018-07-22 20:56:56 -07:00
Slava Pestov
fc3bc76b9a ASTScope: Hack it up for removal of multiple parameter lists
A better approach would be to split off ASTScopeKind::AbstractFunctionSelf
from ASTScopeKind::AbstractFunctionParams, but for now, hack things up at
the boundary to match the old behavior.
2018-07-22 20:56:56 -07:00
John McCall
584146f3f8 Allow a closure-parent ASTScope to be formed from any number of exprs. NFC.
Yield statements will allow an arbitrary number of operands --- like
calls, except we're going to skip over the tuple mistake. :)
2018-07-05 02:48:41 -04: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
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Doug Gregor
a92d8d5760 [Cleanup] Reduce dependencies on swift/AST/LazyResolver.h. 2017-10-10 10:01:39 -07:00
Rintaro Ishizaki
61fd649081 [AST] Eliminate ForStmt
RIP
2017-08-04 23:27:22 +09:00
Rintaro Ishizaki
a375267e5c [ASTScope] Remove ForStmt support. 2017-08-04 23:27:22 +09:00
Slava Pestov
732b215b88 Merge pull request #9413 from rintaro/ast-eliminate-ifconfigstmt
[AST] Eliminate IfConfigStmt
2017-06-16 15:39:47 -07:00
Slava Pestov
51aebd2127 AST: Fix name lookup from within lazy property initializers
Allow instance properties and methods to be referenced from
within a lazy property initializer, with or without explicit
'self.' qualification.

The old behavior in Swift 3 was an incredible combination
of odd quirks:

- If the lazy property had an explicitly-written type, it was
  possible to reference instance members from the initializer
  expression by explicitly prefixing 'self.'.

- However, if the lazy property type is inferred, it would
  first be type checked in the initializer context, which
  has no 'self' available.

- Unqualified references to instance members did not work
  at all, because name lookup thought the "location" of the
  lookup was outside of the body of the getter.

- Unqualified references to static properties worked, however
  unqualified references to static methods did not, and
  produced a bogus diagnostic, because one part of the name
  lookup code thought that initializers were "instance
  context" and another thought they were "static context".

This patch improves on the old behavior with the following
fixes:

- Give PatternBindingInitializers associated with lazy
  properties an implicit 'self' declaration for use by
  name lookup.

- In order to allow "re-parenting" the initializer after it
  has been type checked into the body of the getter, "steal"
  the initializer's 'self' when buiding the getter.

- Fix up name lookup and make it aware of the implicit
  'self' decl of a PatternBindingInitializer.

This improves upon an earlier fix for this issue by Doug Gregor
which only worked with ASTScope enabled; the new fix is more
general and shares logic between the two name lookup
implementations.

Fixes <rdar://problem/16888679>, <https://bugs.swift.org/browse/SR-48>,
<https://bugs.swift.org/browse/SR-2203>,
<https://bugs.swift.org/browse/SR-4663>, and the countless other
dupes of this issue.
2017-05-24 18:59:48 -07:00
Rintaro Ishizaki
de7f2f713a [ASTScope] Eliminate isRealTopLevelCodeDecl function
Now that, all TopLevelCodeDecl is real. Just don't need this.
2017-05-16 12:19:55 +09:00
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
Jordan Rose
4cdb597b23 Rename VTablePlaceholderDecl to MissingMemberDecl.
As such, we no longer insert two placeholders for initializers that
need two vtable slots; instead we record that in the
MissingMemberDecl. I can see MissingMemberDecl growing to be something
we'd actually show to users, that can be used for other kinds of
declarations that don't have vtable entries, but for now I'm not going
to worry about any of that.
2017-05-10 11:55:55 -06:00
Jordan Rose
82930033d2 Add VTablePlaceholderDecl (but don't hook it up to anything yet). 2017-05-10 11:55:54 -06:00
Graydon Hoare
3a79d83233 Forward declare TypeRepr in TypeLoc.h, adjust other code to compensate. 2017-04-18 11:12:53 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Slava Pestov
41eba98902 Gardening: Fix some unused variable warnings in no-assert builds 2017-02-15 12:57:35 -08:00