Commit Graph

413 Commits

Author SHA1 Message Date
Doug Gregor
ea20a1d137 [AST] Add DeclContext::get(Syntactic|Semantic)Depth.
Utilities functions used when comparing declaration contexts. Only the syntactic form is currently used (for the owning DC of a generic environment).
2017-06-01 08:25:42 -07:00
Alex Hoppen
f302afc97f Unify approach to printing declaration names (#9320)
Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:25:20 -07:00
Slava Pestov
5197f38cda AST/Serialization: Some assertions for extensions
These helped me rule out my first theory about another bug, even
though it turned out to be unrelated.
2017-05-22 14:18:23 -07:00
Doug Gregor
f792aeaf1a [AST] Teach the AST verifier not to deserialize generic environments.
The AST verifier was causing deserialization of generic environments,
which slows things down considerably and affects our ability to test
for laziness in deserialization. Prevent it from doing so---and only
do the extra checkig if something else deserialized the generic
environment already.

... except there are some cases where it happens through means that
are harder to control (e.g., the AST walker for patterns) that need
more thought.
2017-05-16 11:03:15 -07:00
Slava Pestov
2fe863266c AST: Fix crashes when name lookup finds declarations outside of a protocol or extension that's nested in another type
When performing a name lookup from inside of a protocol
or extension, skip directly to the source file context
when we are done visiting the protocol or extension.

Otherwise, if we have invalid code where the protocol
or extension is nested inside another type, we might
find a member whose type contains generic parameters
of the outer type; these parameters will not resolve,
since we do not model protocols or extensions nested
inside generic contexts (yet?).

This supercedes an earlier workaround for a similar
issue; the new workaround fixes more crashes.

This is needed to avoid crasher regressions with an
upcoming patch.
2017-05-07 03:01:47 -07:00
ematejska
75a1dcaf28 Merge pull request #9098 from KingOfBrian/feature/SE-0169
SE-0169: Add support for shared private
2017-05-02 16:12:17 -07:00
Brian King
0dce9b7e3d Store the private scope context in the AccessScope constructor to fix equality support 2017-04-28 17:02:04 -04:00
Graydon Hoare
b5292f04f8 Add an assortment of new "always-on" metrics. 2017-04-28 13:56:13 -07:00
Brian King
0a1d52e738 Update the language and method names to avoid the term 'shared private' 2017-04-28 16:37:00 -04:00
Brian King
b3d44e06fa Do not use GNU ternary extension 2017-04-28 15:52:11 -04:00
Brian King
5447443c5b Add support for sharing the private scope between type declaration and extensions in Swift 4 2017-04-28 10:02:49 -04:00
David Hart
ecdcac5aa2 Resolve crasher 28704 (#8158)
This crash happens because shouldAddSelfFixit (a check for the expected_self_before_reference diagnotic) performs name lookup inside the parser, which causes a search for extensions, which triggers the mangler, which can get confused if we are in an unfinished declaration (a PatternBindingInitilizer in this case).

A cleaner fix would be to move that logic inside Sema, but it would require much more refactoring that I don’t feel comfortable doing. Instead, this band-aid checks if the innermost type is inside a local context. If that’s the case, we can ignore the search for extensions.
2017-03-17 18:43:23 -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
880803aaba AST: Initial plumbing for generic subscripts 2017-02-19 21:34:26 -08:00
Slava Pestov
41eba98902 Gardening: Fix some unused variable warnings in no-assert builds 2017-02-15 12:57:35 -08:00
Slava Pestov
bd4f31025f AST: GenericEnvironment::mapTypeIntoContext() no longer needs to take a ModuleDecl
Now, use LookUpConformanceInSignature instead.
2017-02-07 19:25:34 -08:00
Slava Pestov
d65d1d25f9 Sema: Diagnostics for @_inlineable, @_versioned and Swift 4 default arguments model
Piggybacks some resilience diagnostics onto the availability
checking code.

Public and versioned functions with inlineable bodies can only
reference other public and internal entities, since the SIL code
for the function body is serialized and stored as part of the
module.

This includes @_transparent functions, @_inlineable functions,
accessors for @_inlineable storage, @inline(__always) functions,
and in Swift 4 mode, default argument expressions.

The new checks are a source-breaking change, however we don't
guarantee source compatibility for underscored attributes.

The new ABI and tests for the default argument model will come in
subsequent commits.
2017-01-09 16:59:13 -08:00
Slava Pestov
5eb16e6b34 Include-what-you-use: Initializer.h should not be pulled in from AST.h 2017-01-09 16:46:31 -08:00
Hugh Bellamy
7a5ef4bdd1 Support building swift/AST with MSVC on Windows 2017-01-09 09:05:06 +00:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
2555135bbd AST: Remove DeclContext::isValidGenericContext()
This is intended to have no functional effect, but there was a
minor change to a diagnostic in invalid code in the tests for the
unfinished ASTScope code; I hope I didn't break anything more
fundamental there.
2017-01-04 01:08:28 -08:00
Slava Pestov
43ce2e7e1c AST: Simplify DeclContext::getGeneric{Signature,Environment}OfContext()
There's no need to walk up from a function or type context -- if
no generic signature (or environment) is set, the parent won't have
one, either, and if we're in the middle of validating the child
context, using the parent's signature or environment to resolve
dependent types is just wrong.
2017-01-04 01:08:28 -08:00
Slava Pestov
a230bde7e7 AST: Clean up getDeclaredType() and friends 2017-01-03 23:40:47 -08:00
practicalswift
b253b21014 [gardening] Make sure argument names in comments match the actual parameter names 2016-12-21 22:56:01 +01:00
Slava Pestov
4fedd54016 AST: DeclContext::dumpContext() prints to llvm::errs() by default 2016-12-21 14:20:25 -05:00
Slava Pestov
fb0f372e94 AST: Move mapType{In,OutOf}Context() out of ArchetypeBuilder and clean up headers
- The DeclContext versions of these methods have equivalents
  on the DeclContext class; use them instead.

- The GenericEnvironment versions of these methods are now
  static methods on the GenericEnvironment class. Note that
  these are not made redundant by the instance methods on
  GenericEnvironment, since the static methods can also be
  called with a null GenericEnvironment, in which case they
  just assert that the type is fully concrete.

- Remove some unnecessary #includes of ArchetypeBuilder.h
  and GenericEnvironment.h. Now changes to these files
  result in a lot less recompilation.
2016-12-18 19:55:41 -08:00
Slava Pestov
d43e79397b AST: Tighter asserts for DeclContext::mapType{Into,OutOf}Context() 2016-12-17 16:28:18 -08:00
Joe Groff
57d9ad0a03 Remove Module parameter from GenericEnvironment::mapTypeOutOfContext.
The substitution only replaces archetypes with abstract generic parameters, so no conformance lookup is necessary, and we can provide a "lookup" callback now that just vends abstract conformances.

(Ideally, we'd be able to do this for mapTypeIntoContext too, but we run into problems with generic signatures with same-type constraints on associated types with protocol requirements. Mapping `t_0_0.AssocType` into such a context will require conformance lookup for the concrete type replacement, since same-type Requirements don't preserve the conformances that satisfy the protocol requirements for the same-type relationship.)
2016-12-15 10:56:19 -08:00
Doug Gregor
8852937beb [AST] Optimize lazy-member storage for nominal type and extension declarations.
Save two pointers of storage in IterableDeclContext (a base class of
nominal type and extension declarations) by storing the lazy member
loader + context data in an ASTContext side table. It also makes it
easier to add more lazy context information later on.
2016-12-12 08:27:28 -08:00
Slava Pestov
63178e84d2 AST: Improve robustness with invalid nesting of extensions in generic context
Extensions cannot capture generic parameters from outer contexts.
Their generic parameter list does not point to the outer
parameter list, the signature does not contain outer parameters
and they do not appear in the extension's generic environment.

Furthermore, the depth/index of the extension's parameters may
clash with outer parameters, which would break all kinds of
invariants.

This patch changes these DeclContext methods to return false or
nullptr even if an extension is contained in a generic context:

- isGenericContext()
- getGenericParamsOfContext()
- getGenericSignatureOfContext()
- getGenericEnvironmentOfContext()
2016-12-06 09:41:30 -08:00
Doug Gregor
553216a11e Address most of Slava's commentary on this PR. 2016-12-05 22:44:51 -08:00
Doug Gregor
38671e2771 [AST] Hide DeclContext::getAsGenericTypeOrGenericTypeExtensionContext().
This method gets the GenericTypeDecl for a typealias, nominal type, or
extension thereof. While the result is typed as GenericTypeDecl, it's
not always generic, so rename it accordingly.

An audit of the callers illustrated that they should be using
different entrypoints anyway, so fix all of the callers and make this
function private.
2016-12-05 22:42:03 -08:00
Doug Gregor
37bb4d1eae [AST] Make typealiases not "type contexts"
DeclContext's nomenclature around "type contexts" is confusing,
because it essentially means "nominal type contexts", e.g.,
struct/class/enum/protocol and extensions thereof. This implies the
presence of a 'Self' type, the ability to have members, etc.

However, typealiases are also currently classified as "type
contexts", despite not having a reasonable 'Self' type, which breaks
in various places. Stop classifying typealiases as "type contexts".
2016-12-05 22:42:03 -08:00
Argyrios Kyrtzidis
b0705b455a [code-completion] Fix assertion hit when calling 'DeclContext::getResilienceExpansion()' with invalid code
Fixes:
	validation-test/IDE/crashers/074-swift-valuedecl-geteffectiveaccess.swift
	validation-test/IDE/crashers/095-swift-declcontext-getresilienceexpansion.swift
2016-12-05 14:39:53 -08:00
Doug Gregor
bcde6567d5 [AST] Introduce DeclContext::mapType(Into|OutOf)Context()
Use them to eliminate some more instances of getSelfTypeInContext().
2016-12-02 15:31:04 -08:00
Slava Pestov
9a4c740baf AST: Remove DeclContext::isProtocolSelf() 2016-12-02 12:21:55 -08:00
Slava Pestov
b4d11338ec AST: Push ValueDecl::{has,get,set}Type() down to VarDecl
After recent changes, this asserts on all decls that are not VarDecls,
so we can just enforce that statically now. Interestingly, this turns
up some dead code which would have asserted immediately if called.

Also, replace AnyFunctionRef::getType() with
AnyFunctionRef::getInterfaceType(), since the old
AnyFunctionRef::getType() would just assert when called on
a Decl.
2016-12-01 19:28:13 -08:00
Slava Pestov
2d83a79c2c AST: Remove TypeDecl::getDeclaredType()
A pointless use of polymorphism -- the result values are not
interchangeable in any practical sense:

- For GenericTypeParamDecls, this returned getDeclaredInterfaceType(),
  which is an interface type.

- For AssociatedTypeDecls, this returned the sugared AssociatedTypeType,
  which desugars to an archetype.

- For TypeAliasDecls, this returned TypeAliasDecl::getAliasType(),
  which desugars to a type containing archetypes.

- For NominalTypeDecls, this returned NominalTypeDecl::getDeclaredType(),
  which is the unbound generic type, a special case used for inferring
  generic arguments when they're not written in source.
2016-12-01 13:00:18 -08:00
Slava Pestov
8bdbe774e0 AST: Don't call hasType()/getType()/setType() on SubscriptDecls 2016-12-01 13:00:17 -08:00
Joe Groff
5fa4d0917c Nested functions should be compiled resiliently only if nested in a resilient context.
Fixes rdar://problem/29413845, a bug where we would mistakenly flag `@inline(__always)` nested functions as "fragile" even if they appeared nested inside private, internal, or nonfragile public contexts.
2016-11-30 13:29:23 -08:00
Slava Pestov
09980dd3c1 AST: getType() => getInterfaceType() 2016-11-29 03:05:26 -07:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Aleksey Gaponov
3419925ff1 [SR-2209] Fix access scope diagnostics for top-level declarations. 2016-11-09 21:18:37 +01:00
Aleksey Gaponov
f51b2d12c4 [SR-2209] Make a real AccessScope class and use it in access checking.
1. Add new AccessScope type that just wraps a plain DeclContext.
2. Propagate it into all uses of "ValueDecl::getFormalAccessScope".
3. Turn all operations that combine access scopes into methods on AccessScope.
4. Add the "private" flag to distinguish "private" from "fileprivate"
scope for top-level DeclContext.
2016-11-04 12:42:38 +01:00
Slava Pestov
4780b0bcdf AST: Introduce @_inlineable attribute
This attribute causes a function's body to be serialized, but unlike
@_transparent and @inline(__always), does not force it to be inlined.
2016-11-01 21:14:35 -07:00
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Slava Pestov
a9c68c0736 AST: Remove archetype from AbstractTypeParamDecl
There's a bit of a hack to deal with generic typealiases, but
overall this makes things more logical.

This is the last big refactoring before we can allow constrained
extensions to make generic parameters concrete. All that remains
is a small set of changes to SIL type lowering, and retooling
some diagnostics in Sema.
2016-09-22 19:48:30 -07:00
Doug Gregor
5e25d25c96 [AST] Separate the DeclContexts for different pattern binding entries in a pattern binding decl. 2016-09-02 10:39:19 -07:00
Slava Pestov
1c1ab0b83a AST: Introduce new GenericEnvironment class
A GenericEnvironment stores the mapping between GenericTypeParamTypes
and context archetypes (or eventually, concrete types, once we allow
extensions to constrain a generic parameter to a concrete type).

The goals here are two-fold:

- Eliminate the GenericTypeParamDecl::getArchetype() method, and
  always use mapTypeIntoContext() instead

- Replace SILFunction::ContextGenericParams with a GenericEnvironment

This patch adds the new data type as well as serializer and AST
verifier support. but nothing else uses it yet.

Note that GenericSignature::get() now asserts if there are no
generic parameters, instead of returning null. This requires a
few tweaks here and there.
2016-08-28 13:51:36 -07:00