Commit Graph

514 Commits

Author SHA1 Message Date
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
David Ungar
5c8828b486 git-clang-format my changes 2017-08-24 20:09:19 -07:00
David Ungar
27aaa549ad separate out addMemberAndAlternatesToExtension 2017-08-24 20:09:18 -07:00
David Ungar
bd6a9c0432 factor out loadAllMembersIntoExtension 2017-08-24 20:09:17 -07:00
David Ungar
f8b524342d factor out for-loop body into insertMembersAndAlternates 2017-08-24 20:09:16 -07:00
David Ungar
0f57a83229 factor out collectMembersToAdd 2017-08-24 20:09:16 -07:00
David Ungar
a2e7ea1237 separate out loadAllMembersOfObjcContainer 2017-08-24 20:09:16 -07:00
David Ungar
5662c4b5dc Remove redundant getMembers
Also make LazyMemberLoader abstract
Add "final" to (Class|Protocol|Enum|Struct)Decl classes
2017-08-18 20:09:20 -07:00
swift-ci
5b15da4b32 Merge remote-tracking branch 'origin/master' into master-next 2017-07-17 14:08:49 -07:00
Jordan Rose
925f2913f8 [ClangImporter] Add direct access for import-as-member types.
This avoids having to bring in all members (and extensions!) for an
outer type just to look up a nested type. In the test case attached
(reduced from the project in SR-5284), this actually led to a circular
dependency between deserialization and the importer, which resulted in
a compiler crash.

This is not a new problem, but it's more important with the release of
Swift 4, where a number of Apple SDK types are now newly imported as
member types. (The one in the original bug was
NSView.AutoresizingMask, formerly NSAutoresizingMaskOptions.) Since we
always use the Swift 4 name for cross-references, this affected
everyone, even those still compiling in Swift 3 mode.

https://bugs.swift.org/browse/SR-5284
2017-07-13 17:56:40 -07:00
swift-ci
e98182387b Merge remote-tracking branch 'origin/master' into master-next 2017-07-11 12:23:35 -07:00
John McCall
0e89efa1c8 Bridge types during import only if we are in a fully-bridgeable context.
Somehow the logic had slipped so that we were basing this decision purely
on the ImportTypeKind and not on whether the broader context is bridgeable.
This was allowing us to use bridged types when e.g. importing the results
and parameters of C function pointer types, which is really bad.

Also, when importing a reference to a typedef of block type, do not use
the typedef in a non-bridgeable context.  We import typedefs of block type
as fully-bridged types, but this means that it is invalid to import a type
using the typedef in a context where the original C type must be used.
Similarly, make sure we use a properly-imported underlying type of the
typedef when the typedef itself is unavailable.

Also, extend the special behavior of block typedefs to abstract-function
typedefs, which seems to be consistent with the expected behavior of the
tests.

Finally, I changed importType to take a new Bridgeability enum instead of
a raw canFullyBridgeTypes bool.  At the time, I was doing that because I
was going to make it tri-valued; that turned out to be unnecessary, but I
think it's an improvement anyway.
2017-07-09 13:53:19 -04:00
Michael Gottesman
78713ce07f Merge pull request #10519 from jrose-apple/ModuleMacro-master-next
WIP getting master-next up and running with clang::ModuleMacro
2017-06-30 14:52:09 -07:00
Jordan Rose
a8bc132565 [ClangImporter] Make conformance loading lazier.
Previously, the importer queued up conformances to complete once it
was done importing the current batch of declarations. However, if
there was a serialized Swift module that extended an imported type to
add a conformance in exactly the wrong way, the importer could end up
asking for that conformance later---even before the reference to the
imported type was resolved. This led to a crash in the deserializer
"while reading conformance for type X".

Instead of this "pending actions" queue, we can just use the
mechanisms already in place for lazily loading conformances. That way
they'll get filled out on demand, which is better all around anyway.
This does mean putting the requirement signature into the "lazy" part
of the conformance, though.

This does as a side effect mean that /all/ of the witnesses for the
imported conformance may be opaque---that is, they will never be
devirtualized to a particular implementation. However, they previously
would have referred to methods implemented in Objective-C anyway,
which are always dispatched with objc_msgSend. So this should have no
practical effect.

rdar://problem/32346184
2017-06-29 15:50:09 -07:00
Doug Gregor
aa215e7e54 [Clang importer] Make sure that the first argument of Set/Dictionary types are Hashable.
Extend the check to make sure that the first type argument to an
imported Set or Dictionary type is Hashable actually checks
struct/enum types for Hashable conformances.

Fixes rdar://problem/30622665.
2017-06-26 13:08:39 -07:00
Jordan Rose
c3d6be64ab WIP Update to use clang::ModuleMacro instead of clang::MacroInfo.
Untested and still missing a few pieces.
2017-06-23 16:04:24 -07:00
Huon Wilson
1c82b7d3f5 [ClangImporter] Don't resugar NSPointer for the error out parameter of throws functions.
This breaks a cycle with a function in Foundation, but isn't a complete
fix: it will be similarly problematic if a function that can't have the
throws conversion is added.
2017-05-18 17:51:03 -07:00
Jordan Rose
ec23dcaaac [ClangImporter] Find Swift 3 / 4 names via dynamic lookup too.
Finishes rdar://problem/29170671
2017-05-13 14:53:18 -07:00
Jordan Rose
6c098033de Lift the decision of whether a method needs a vtable slot up to AST.
This lets us serialize that decision, which means we can conceivably
/change/ the decision in later versions of the compiler without
breaking existing code. More immediately, it's groundwork that will
eventually allow us to drop decls from the AST without affecting
vtable layout.

This isn't actually a great answer; what we really want is for SIL
vtables to be serialized consistently and treated as the point of
truth. But that would be more change than we're comfortable taking in
the Swift 4 timeframe.

First part of rdar://problem/31878396.
2017-05-04 17:49:47 -07:00
Jordan Rose
cb9b9ea734 [ClangImporter] Always import types under their Swift 4 name.
This means all cross-module references and all mangled names will
consistently use the Swift 4 name (the canonical type), no special
handling required.

The main thing we lose here is that the Swift 4 names of imported
types become usable in Swift 3 mode without any diagnostics, similar
to how most language features introduced in Swift 4 are available in
Swift 3 mode. It also implies that the Swift 4 name will show up in
demangled names.

rdar://problem/31616162
2017-04-26 13:07:03 -07:00
Adrian Prantl
ca30cac2e5 Fix use-after-free introduced by 65668c9d82.
rdar://problem/31460012
2017-04-05 15:11:22 -07:00
David Farler
65668c9d82 Cache Code Completion results from PCH files
- Add CompilerInvocation::getPCHHash
  This will be used when creating a unique filename for a persistent
  precompiled bridging header.

- Automatically generate and use a precompiled briding header
  When we're given both -import-objc-header and -pch-output-dir
  arguments, we will try to:
  - Validate what we think the PCH filename should be for the bridging
    header, based on the Swift PCH hash and the clang module hash.
    - If we're successful, we'll just use it.
    - If it's out of date or something else is wrong, we'll try to
      emit it.
  - This gives us a single filename which we can `stat` to check for the
    validity of our code completion cache, which is keyed off of module
    name, module filename, and module file age.

- Cache code completion results from imported modules
  If we just have a single .PCH file imported, we can use that file as
  part of the key used to cache declarations in a module.  Because
  multiple files can contribute to the __ObjC module, we've always given
  it the phony filename "<imports>", which never exists, so `stat`-ing it
  always fails and we never cache declarations in it.

  This is extremely problematic for projects with huge bridging headers.
  In the case where we have a single PCH import, this can bring warm code
  completion times down to about 500ms from over 2-3s, so it can provide a
  nice performance win for IDEs.

- Add a new test that performs two code-completion requests with a bridging header.
- Add some -pch-output-dir flags to existing SourceKit tests that import a bridging
  header.

rdar://problem/31198982
2017-04-04 20:44:33 -07:00
Jordan Rose
0d347ac127 [ClangImporter] Make sure fake locations are always in /some/ buffer. (#8303)
We synthesize fake source locations for module imports that come from
Swift code; these locations have to be both valid and distinct for
Clang to use. We've mostly been getting away with simply making fake
offsets from the main file, but after the offsets start exceeding the
size of the buffer they start pointing into some /other/ file, and
then if Clang's SourceManager tries to order those locations it gets
/very/ confused.

This commit fixes that by allocating a 256K buffer of zeros and using
offsets into that instead. The hope is that a read-only mmap'd buffer
of zeros that never gets read (except possibly to look for newlines)
will be cheap to allocate.

(Why not just make the main file buffer 256K? Because we actually try
to parse that, and there's really no reason for the lexer to go crawl
through that file eagerly.)

This test case isn't the best because it doesn't actually fail in the
old code, but if only the assertion was added we at least hit that.
I did verify with the reproducing project I have that we no longer
hit this issue.

rdar://problem/30924269
2017-03-24 16:00:50 -07:00
Huon Wilson
09cd885140 [Frontend] Handle imports in the C code tied to a Swift module.
The underlying module and/or bridging header are likely to contain
module imports that we need to know about.
2017-03-17 18:46:09 -07:00
Graydon Hoare
94f30aacd5 Merge pull request #7705 from graydon/rdar-30615193-defer-module-import-from-bridging-header-until-finished-parse
[Clang Importer] Defer module imports to end of bridging-header parse.
2017-02-27 22:38:02 -08:00
Graydon Hoare
2a8fd72b46 [Clang Importer] Defer module imports to end of bridging-header parse.
There is a subtle incompatibility between the way bridging headers handle
module imports and the way clang's normal module-loading works (as done
by -emit-pch in bridging PCH, in particular).

When importing a submodule, Swift implicitly imports its supermodule. This
is part of Swift's treatment of modules and fine, we're not changing it
here.

But if client code imports a submodule, then tries to use a type that is
only defined in its supermodule, not the submodule, this _should_ cause
a parse error (and does in clang alone, or when generating a PCH).
Unfortunately Swift's "implicit parent import" currently happens
eagerly, so the supermodule is imported and its type is defined as soon
as the submodule is imported, which in turn suppresses the error.

This in turn means that client code thinks their code "works" and then
"breaks" when they turn on bridging PCH. What _should_ happen here is
that the (actually broken) client code should not be accepted in the first
place, neither bridging PCH nor textual bridging-header import.

This commit merely changes textual bridging-header import from eager
import to deferred parent-import, like bridging PCH does. This reconciles
the difference in behaviour between the two, at the cost of a source-compat
break.

rdar://30615193
2017-02-27 15:38:25 -08:00
Graydon Hoare
49231a35e6 [Clang Importer] Make ClangModuleUnit owned by ClangImporter::Implementation. 2017-02-27 15:05:07 -08:00
Huon Wilson
84e0a109a2 [AST] Explicitly track the validation state of Decls.
Previously some decls (TypeAliasDecl and ExtensionDecl) had bits
explicitly marking whether they've been validated, while other decls
just deduced this from hasInterfaceType. The doing the latter doesn't
work when the interface type can be computed before doing full
validation (such as protocols and associatedtypes, which have trivial
interface types), and so an explicit bit is adopted for all decls.
2017-02-24 19:21:33 -08:00
Xi Ge
b32424953e [SourceKit] Add a new request to translate from Objc names to Swift names and vice versa.
Extensive cross-language tooling support needs to bridge decl names between two different languages more freely. This SourceKit request is designed to translate Objc names to Swift names and vice versa. Working similarly to cursor-info requisition, the name translation request requires a Swift reference to a Swift/Clang decl, and the preferred name to translate from, and language kind that the given name belongs to. If the translation succeeds, SourceKit service responds with the corresponding name than belongs to the other kind of language.

Newly introduced keys:

“key.namekind": “source.lang.name.kind.objc” | "source.lang.name.kind.swift"
“key.basename”: “name"
“key.argnames”: [“name"]
“key.selectorpieces”: [“name[:]"]

This commit only implements translation from Objc to Swift.
2017-02-10 17:50:12 -08:00
Doug Gregor
2307e15290 [Clang importer] Compute the requirement signature of imported protocols.
We can also avoid walking the members of said protocols in the
archetype builder and when looking for nested types, because of course
there are no associated types in imported Objective-C protocols.
2017-02-09 23:50:16 -08:00
Jordan Rose
1cf1961fc7 Merge pull request #7007 from jrose-apple/accessor-argument-labels
[Importer] Preserve argument labels even for accessors.
2017-01-27 11:18:44 -08:00
Graydon Hoare
b1a4867e43 Merge pull request #7045 from graydon/tighten-warning-on-implicit-header-import
[Bridging PCH] Followup to narrow cases of implicit-header-import warning.
2017-01-26 12:31:17 -08:00
Graydon Hoare
538a896c0a [Bridging PCH] Followup to narrow cases of implicit-header-import warning. 2017-01-25 20:45:38 -08:00
Jordan Rose
fdbc84f7ec [Importer] Preserve argument labels even for accessors.
The AST verifier is unhappy when an accessor's imported name gets
selector-split but its parameters don't have that recorded. Although
we're not using this for anything today, it seems best to keep the
two in sync.

rdar://problem/29889051
2017-01-25 13:44:25 -08:00
Jordan Rose
4020f49f8e [Verifier] Fix ClangImporter imported decls verification.
Previously it wouldn't run the verifier again if no new modules were
imported, even if more decls had been loaded since last time. This
likely only affects script-mode files (main.swift-like).
2017-01-25 13:44:24 -08:00
Jordan Rose
3411fc380e [ClangImporter] Prefer available enum elements over unavailable ones.
...and avoid making aliases from one unavailable declaration to another.
If it's unavailable, we can just import it as a normal case and not
worry about it. This fixes an issue where Sema would try to diagnose
the body of an "alias" for referring to unavailable declarations.

(Background: enum cases in Swift have to have unique values, so we
import any duplicate values as static properties. Pattern matching
logic has a hack to recognize these particular static properties as
being "case-like".)

This commit also sinks enum element uniqueness checking into importing
the enum, instead of keeping a global map we never consult again. This
should save a small bit of memory.

rdar://problem/30025723
2017-01-23 15:34:20 -08:00
Bob Wilson
34514513fd Merge remote-tracking branch 'origin/master' into master-next 2017-01-15 17:34:17 -08:00
Graydon Hoare
08af6f0c09 [Bridging PCH] Warn on non-redundant implicit bridging-header imports.
We're trying to get rid of implicit bridging-header imports, as a feature.
These are IMPORTED_HEADER blocks left in modules built with bridging
headers, that trigger re-importing the bridging header into any client
that imports the module.

As a half-way measure to deprecating them, we add a warning here that
triggers when an implicit bridging-header import occurs that is _not_
suppressed as redundant by clang.
2017-01-13 15:18:40 -08:00
Graydon Hoare
874dc3b498 [Bridging PCH] Pass .pch bridging headers to clang -import-pch 2017-01-13 15:18:40 -08:00
Graydon Hoare
d709aff91a [Bridging PCH] Populate bridging lookup table when reading MK_PCH module. 2017-01-13 15:18:39 -08:00
Graydon Hoare
2b638dce87 [Bridging PCH] Store ClangImporter::BridgingHeaderLookupTable indirectly. 2017-01-13 15:18:39 -08:00
Saleem Abdulrasool
ad6c40c6f8 Adjust for SVN r290718
Modify the ownership by using `std::unique_ptr` like clang does.
2017-01-08 17:11:30 -08: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
Jordan Rose
b538baaa2a [ClangImporter] Simplify importFunctionType too.
Like 9712c432f, but for functions. No intended functionality change.
2016-12-22 17:32:32 -08:00
Jordan Rose
0f4fa144d0 [ClangImporter] Split out the accessor parts of importMethodType.
There's really not that much code shared between the accessor and
non-accessor cases in importMethodType, so split them up.

The one change here is that previously a method could /think/ it was
an accessor, but not be treated as one if the property decl has a
different getter or setter. Now such a method is just dropped by the
importer completely. It's intended that this is not a behavioral
change in that no real code should have such an AST.

This is building towards always having a consistent type for property
setters added in handlePropertyRedeclaration, which is
rdar://problem/29422993.
2016-12-21 17:53:25 -08:00
Jordan Rose
9712c432fc [ClangImporter] Simplify the importMethodType helper.
Once upon a time this was agnostic of the declaration being imported
(and possibly even still merged with importFunctionType) but that
hasn't been true for a while. If we're passing the ObjCMethodDecl
and ImportedName anyway, we don't need to separately pass the result
type, whether it's noreturn, and the Swift name as separate arguments.

No intended functionality change.
2016-12-21 17:51:59 -08:00
Michael Ilseman
1e42a16247 [Clang Importer] Plumb versions everywhere
Remove all occurrences of a "useSwift2Name" bool, and replace it with
version plumbing. This means that ImportDecl is now entirely
version-based, and the importer Impl knows versions. This will be
needed for marking Swift 3 names as deprecated, when there is a new
Swift 4 name.

NFC.
2016-12-14 19:55:14 -08:00
Michael Ilseman
68737b78c2 [ClangImporter] Refactor name importing to be version based
Rather than use importName using a set of options of what to choose,
phrase the API in terms of language version. Be explicit about what
version is being requested at the call site, as it's a necessary
consideration for the client.
2016-12-03 13:26:08 -08:00
Michael Ilseman
d1efc80b1f [Import Decl] Don’t import as init using omit needless words
Previously, for an Objective-C class method declaration that could be
imported as init, we were making 4 decls:

1) The Swift 2 init
2) The Swift 2 class method decl (suppressing init formation)
3) The Swift 3 init (omitting needless words)
4) The Swift 3 class method decl (suppressing init formation and
   omitting needless words)

Decls 1), 2), and 4) exist for diagnostics and redirect the user at
3). But, 4) does not correspond to any actual Swift version name and
producing it correctly would require the user to understand how
omit-needless-words and other importer magic operates. It provides
very limited value and more importantly gets in the way of future
Clang importer refactoring. We’d like to turn Decl importing into
something that is simpler and language-version parameterized, but
there is no real Swift version to correspond to decl 4).

Therefore we will be making the following decls:

1) The "raw" decl, the name as it would appear to the user if they
   copy-pasted Objective-C code
2) The name as it appeared in Swift 2 (which could be an init)
3) The name as it appeared in Swift 3 (which could be an init and omit
   needless words)

This aligns with the language versions we want to import as in the
future: raw, swift2, swift3, …, and current.

Note that swift-ide-test prunes decls that are unavailable in the
current Swift version, so the Swift 2 non-init decls are not printed
out, though they are still present. Tests were updated and expanded to
ensure this was still the case.
2016-12-01 18:50:40 -08:00