Commit Graph

498 Commits

Author SHA1 Message Date
Doug Gregor
919b6449a4 [Modules] const'ify getUnderlyingClangModule(). NFC 2017-09-14 15:09:18 -07:00
Xi Ge
350ff24495 Suggested by Jordan, make optional SourceFile field explicit. 2017-09-08 21:24:48 -07:00
Xi Ge
ceec130b0a Simplify some code in SourceFile, NFC 2017-09-08 17:19:08 -07:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Slava Pestov
9f8760b942 AST: Remove unused 'resolver' parameter from ModuleDecl::lookupConformance()
... as well as a bunch of downstream plumbing that is no
longer necessary.
2017-09-07 03:36:17 -07:00
Slava Pestov
87a1354444 AST: Remove unnecessary existentialTypeSupported() check
If we're looking up the conformance of an existential type
to a protocol, we don't have to check if the existential
type is supported, because such a type should not have
been formed in the first place.
2017-09-07 03:36:17 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
Slava Pestov
02aed05b6d AST: Remove some dead code 2017-06-16 17:46:00 -07:00
Slava Pestov
c152fee9f8 Sema: A couple of recursion-breaking hacks 2017-06-07 17:19:09 -07:00
Jordan Rose
c0ccdb1626 Change getBaseName to return DeclBaseName instead of Identifier (#9968)
This changes `getBaseName()` on `DeclName` to return a `DeclBaseName`
instead of an `Identifier`. All places that will continue to be
expecting an `Identifier` are changed to call `getBaseIdentifier` which
will later assert that the `DeclName` is actually backed by an
identifier and not a special name.

For transitional purposes, a conversion operator from `DeclBaseName` to
`Identifier` has been added that will be removed again once migration
to DeclBaseName has been completed in other parts of the compiler.

Unify approach to printing declaration names

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:55:03 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Slava Pestov
9c3b514c7e AST: New getExistentialLayout() method on TypeBase and CanType
This consolidates calculations which need to look at every
protocol in an existential type. Soon we will also have to
deal with superclass constrained existentials, so start
updating call sites that look at all protocols to use the
new ExistentialLayout and correctly handle a class constraint
as well.

Also, eventually I will kill off the AnyObject protocol and
model it as a protocol composition with no protocols or
superclass, but the requiresClass() flag set.

This is not quite modeled this way yet and AnyObject still
exists, but the new abstraction is a step in the right
direction.
2017-04-10 17:04:37 -07:00
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -07:00
Bob Wilson
fbc6a28472 Use llvm::MD5::stringifyResult to get a hash string.
llvm r298322 broke the Swift master-next build because it changed MD5Result
to be a struct and not just an array. Rather than a superficial patch to
extract the array, this changes the code to use llvm's stringifyResult
function, which basically addresses one of the FIXMEs in that code.
2017-03-21 10:36:52 -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
Alex Hoppen
dd1c661c16 Merge pull request #8015 from ahoppen/isOperator-gardening
[Gardening] Change calls of getName().isOperator() to isOperator()
2017-03-10 21:10:33 +00:00
Alex Hoppen
1b7055db5a [Gardening] Change calls of getName().isOperator() to isOperator() 2017-03-10 09:06:20 +00:00
Slava Pestov
2777c9b478 AST: Remove TypeBase::gatherAllSubstitutions() 2017-03-08 13:54:31 -08:00
Slava Pestov
c040c71ea9 AST: Remove some unnecessary SubstitutionList copies
ASTContext::getSpecializedConformance() already copies the
substitutions, so remove some AllocateCopy() calls.

Also, add a new overload taking a SubstitutionMap instead.
This allows removing some gatherAllSubstitutions() calls,
which have an allocation inside them.

Finally, remove the now-unused ModuleDecl parameter from
ProtocolConformance::subst() and make it public.
2017-03-07 15:59:05 -08:00
David Farler
431b7ff2af [Syntax] Add Equal '=' token location to TypeAliasDecl
Needed for full-fidelity structured editing.
2017-02-17 12:57:04 -08:00
Slava Pestov
41eba98902 Gardening: Fix some unused variable warnings in no-assert builds 2017-02-15 12:57:35 -08:00
Doug Gregor
579af863c5 Rename ArchetypeBuilder -> GenericSignatureBuilder 2017-02-10 12:46:34 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Slava Pestov
fc3244b2f2 Sema: Remove some redundant conformance lookup callbacks
Now we have LookUpConformanceInModule and
LookUpConformanceInSubstitutionMap.
2017-02-03 19:55:40 -08:00
practicalswift
849b27b406 [gardening] Fix recently introduced \t 2017-01-21 10:31:33 +01:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Hugh Bellamy
cd8427ed41 Fix MSVC static assertion failue 2017-01-19 08:50:46 +00:00
Hugh Bellamy
201ad5d594 Prefix COMPILER_IS_MSVC with SWIFT_ 2017-01-16 22:09:53 +00:00
Hugh Bellamy
cf777d04f5 Introduce and use COMPILER_IS_MSVC 2017-01-15 15:17:18 +00: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
e4abdfc2bd AST: Model protocols nested inside other types
We might allow protocols inside non-generic class/struct/enum
declarations eventually; there's no conceptual difficulty, just
some IRGen and Serialization work that has to happen first.

Also, this fixes a crasher :-)
2017-01-04 00:10:29 -08:00
Slava Pestov
2b05dd9d85 AST: Remove error path that was causing crashes 2017-01-04 00:10:28 -08:00
Slava Pestov
b6d8bbb698 AST: Return abstract conformance for UnresolvedType
We "fake" a conformance of UnresolvedType to any protocol.
Instead of returning a concrete conformance, return an
abstract conformance. The concrete conformance had several
problems leading to further crashes:

- The DC was set to a module, not a type declaration context,
  since there is not type declaration context here.

- The conformance was marked complete even though it was missing
  inherited conformances.
2017-01-04 00:10:28 -08:00
Slava Pestov
7e1bc3c980 AST: Fix calls to protocol extension methods from class methods returning 'Self'
Here, the 'self' value has a dynamic Self type, which we must strip
off when performing the conformance lookup.

Fixes <https://bugs.swift.org/browse/SR-2696>.
2017-01-03 20:13:43 -08:00
Slava Pestov
caa7045ae5 AST: Remove unnecessary ModuleDecl parameter from GenericSignature::getSubstitutions() 2016-12-22 14:33:00 -05:00
Slava Pestov
ed19f2cbe9 AST: Fix gatherAllSubstitutions() for recent change to not adopt archetypes from context
This could lead to verifier failures on invalid nesting of
generic types in generic functions.
2016-12-19 18:49:57 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01: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
Joe Groff
ccfabd1118 Make LookupConformanceFn callbacks return Optional<ProtocolConformanceRef>.
NFC yet, but this is a step toward centralizing error handling policy for failed conformance lookups instead of leaving it ad-hoc.
2016-12-14 18:04:35 -08:00
Michael Gottesman
1af1cbfb76 [gardening] Add a bunch of end namespace comments found by clang-tidy. 2016-12-06 19:22:52 -08:00
Slava Pestov
9caaad442b AST: Don't call hasType()/getType()/setType() on TypeDecls 2016-12-01 13:00:19 -08:00
Slava Pestov
6cbb494ad2 AST: Give all ValueDecls an interface type
Previously, getInterfaceType() would return getType() if no
interface type was set. Instead, always set an interface type
explicitly.

Eventually we want to remove getType() altogether, and this
brings us one step closer to this goal.

Note that ParamDecls are excempt from this treatment, because
they don't have a proper interface type yet. Cleaning this up
requires more effort.
2016-11-29 03:05:25 -07:00
Slava Pestov
c5b461924a AST: Don't canonicalize types when caching substitutions
This causes us to lose sugar in some cases; needed for the next patch.
2016-11-26 01:30:32 -05:00
Graydon Hoare
7c1dc18b64 Revert "Give all declarations an explicit interface type" 2016-11-24 09:55:27 -08:00
Slava Pestov
ee56292808 AST: Give all ValueDecls an interface type
Previously, getInterfaceType() would return getType() if no
interface type was set. Instead, always set an interface type
explicitly.

Eventually we want to remove getType() altogether, and this
brings us one step closer to this goal.

Note that ParamDecls are excempt from this treatment, because
they don't have a proper interface type yet. Cleaning this up
requires more effort.
2016-11-24 02:35:21 -05:00