Commit Graph

1537 Commits

Author SHA1 Message Date
Erik Eckstein
b11b60e658 SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-14 14:54:18 -07:00
Slava Pestov
47d7cacb98 IRGen: Fix emission of builtin reflection descriptors in multi-threaded mode
Ensure they get emitted at the end of the job by the dispatcher, and
also use a proper mangling and shared linkage for these symbols so
that if multiple threads emit the same descriptor it gets merged.

The new tests attempt to exercise these scenarios.

Fixes <rdar://problem/27906876>.
2016-09-12 19:44:53 -07:00
Michael Gottesman
fa1bb95923 Merge remote-tracking branch 'origin/master' into master-next 2016-08-30 19:50:12 -07:00
Joe Groff
b5ada394a7 IRGen: Correctly register conformances for generic ObjC classes.
They aren't really generic at runtime, so register them as conformances on the nongeneric class. Fixes rdar://problem/27869089.
2016-08-16 12:59:03 -07:00
John McCall
afdda3d107 Implement SE-0117.
One minor revision: this lifts the proposed restriction against
overriding a non-open method with an open one.  On reflection,
that was inconsistent with the existing rule permitting non-public
methods to be overridden with public ones.  The restriction on
subclassing a non-open class with an open class remains, and is
in fact consistent with the existing access rule.
2016-08-02 07:46:38 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Mark Lacey
1c00ac4c6d Merge remote-tracking branch 'origin/master' into master-next
Conflicts:
	lib/IRGen/IRGen.cpp
	test/DebugInfo/parent-scope.swift
2016-07-15 19:23:53 -07:00
Saleem Abdulrasool
7352392830 IRGen: add support for DLL Storage semantics
Add initial support for modelling DLL Storage semantics for global values.  This
is needed to support the indirect addressing mechanism used on Windows.
2016-07-06 18:03:57 -07:00
Michael Gottesman
3c603ab18b Merge remote-tracking branch 'origin/master' into master-next 2016-07-01 18:44:21 -07:00
Jordan Rose
09ae7abf1d Merge pull request #3253 from jrose-apple/ForeignKind
Mark the Dispatch classes as a new kind of "foreign" class.

rdar://problem/26850367
2016-06-30 14:49:20 -07:00
Jordan Rose
3b6e40c030 Use ClassDecl::ForeignKind to model Clang's objc_runtime_visible.
We're now correctly checking for inheritance, adding @objc methods,
and adding @objc protocols for both CF types and objc_runtime_visible
classes (those without visible symbols). The latter is used for some
of the types in Dispatch, which has exposed some of the classes that
were considered implementation details on past OSs.

We still don't properly implement using 'as?' to check conformance to
a Swift protocol for a CF or objc_runtime_visible type, but we can do
that later.

rdar://problem/26850367
2016-06-30 11:20:58 -07:00
Jordan Rose
53118e9a5f Split the "Foreign" flag into a ForeignKind enum.
This flag tracks whether we have a special kind of imported class
that has limitations in what you can do with it. Currently it's
used for two things: CF classes, and the magic "Protocol" class used
to represent Objective-C protocol metadata. I'm planning to add a
third to handle classes with the recently-added objc_runtime_visible
attribute, which describes an Objective-C class whose runtime symbols
are hidden (forcibly preventing categories and subclassing). This is
used for some of the types in Dispatch, which has exposed some of the
classes that were considered implementation details on past OSs.

I'm splitting the flag into an enum rather than just marking the
Dispatch classes with the existing flag because we still need to
be able to /cast/ to the Dispatch types (which you can't do with CF
types today) and because they deserve better than to be lumped in
with CF for diagnostic purposes.

Groundwork for rdar://problem/26850367, which is that Swift will
happily let you extend the new Dispatch classes but then fails to find
the symbols at link-time.
2016-06-29 14:20:21 -07:00
Adrian Prantl
c30286add0 Remove an overzealous assertion and update an explanatory comment.
rdar://problem/27086637
2016-06-29 14:16:16 -07:00
Adrian Prantl
75e10a66cc This fixes a bot failure in the LLDB testsuite.
This removes an assertion that no longer serves its purpose and
relaxes the IRBuilder checks for debug info when generating code
inside the debugger.

When LLDB is JIT-compiling expressions, it will not generate a
SWIFT_ENTRY_POINT_FUNCTION (there will be one per expression)
but it will still generate the equivalent of top level code.

rdar://problem/26955467
2016-06-28 10:33:40 -07:00
Adrian Prantl
935b702a07 Add an assertion to IRBuilder to prevent function calls with no debug location
It is not valid LLVM IR to have a function call without a location to an
inlinable function inside a function with debug info — this makes it impossible
to construct inline information.

This patch adds an assertion and fixes up several places across IRGen where
such a situation could happen.

rdar://problem/26955467
2016-06-27 19:04:51 -07:00
Vedant Kumar
1409a445d9 [stable-merge] Adopt new setUnnamedAddr API 2016-06-27 11:12:28 -07:00
Mark Lacey
d5cc962b11 Fix leak in type metadata emission.
We were releasing the owned pointer rather than just letting it get
deleted when the unique_ptr goes out of scope.

Fixes rdar://problem/26245737.
2016-06-23 13:42:07 -07:00
Slava Pestov
4aa1aa7202 IRGen: Preliminary support for nested generic types
For now, just run the existing SILGen test to completion. I'll work on
more tests later, I wanted to check this stuff in before it bitrots
any further.
2016-06-23 00:01:41 -07:00
Erik Eckstein
d23551a25b Don't generate code for transparent functions.
They are mandatory inlined anyway. Therefore the binary code of transparent functions is not used in most cases.
In case the address of a transparent function is taken, the main program (which deserialized the transparent function) generates code for it and treats it as shared function.

This reduces the stdlib code size by 2.8%.
2016-06-16 15:59:00 +02:00
Slava Pestov
c4191dea19 Merge pull request #2857 from slavapestov/revert-public-fragile-hack
Revert public fragile hack
2016-06-07 13:17:42 -07:00
Adrian Prantl
4cee546841 Emit debug info for global variables without storage.
As with local variables this is done by emitting a constant 0 location
and a type of size zero.


<rdar://problem/26660971>
2016-06-06 17:06:20 -07:00
Slava Pestov
8f17c436e3 Revert "IRGen: Remove special handling of fragile entities in LinkEntity"
This reverts commit 8e439904e2.

See the discussion here for details:

<672356047d>
2016-06-06 17:28:55 -06:00
Slava Pestov
60dff01093 Reflection: Simplify associated type metadata emission
Instead of hooking into nominal type and extension emission
and walking all conformances of those declarations, let's
just directly hook into the logic for emitting conformances.

This fixes an issue where we would apparently emit duplicate
conformances, as well as unnecessary conformances that are
defined elsewhere.
2016-05-26 19:33:00 -07:00
John McCall
79c83c7303 Teach IRGen to tell Clang to emit lazy definitions on demand.
Previously, we had hacks in place to eagerly emit everything in
the global ExternalDefinitions list.  These can now be removed,
at least at the IRGen layer.
2016-05-18 22:48:45 -07:00
John McCall
06c65464cf Don't crash if an error is emitted by Clang IR-generation.
Clang IR-generation can fail.  When it does this, it destroys the
module. Previously, we were blithely assuming this couldn't happen,
and so we would crash on the deallocated module.  Delay the
finalization of the Clang code generator until our own module
finalization, which is a more appropriate place for it anyway,
and then just bail out of the last few steps if Clang fails.
2016-05-17 12:38:53 -07:00
David Farler
a1ff1e6a7b Eagerly emit reflection metadata as decls are emitted
Rather than collection nominal type and extension decls and emit
reflection metadata records in one go, we can emit them as they
are encountered and instead collection builtin types referenced
by those at the end.
2016-04-29 17:07:55 -07:00
John McCall
6c92c324f6 Rename IRGenModuleDispatcher to just IRGenerator and transfer
ownership of some of the basic structures to it.
2016-04-27 09:42:03 -07:00
David Farler
ff67f7f6af [GenReflection] Emit associated type reflection metadata via extensions
Don't leave behind conformances gotten through extensions when
emitting associated type reflection metadata.
2016-04-15 17:48:27 -07:00
David Farler
263af75590 Revert "Stamp Swift binaries with the reflection version"
This reverts commit 437d3f2043.
2016-04-15 12:26:27 -07:00
Slava Pestov
824bd7544d IRGen: Emit typerefs for all builtin types referenced from reflection metadata sections
In order to perform layout, the remote mirrors library needs to know
about the size, alignment and extra inhabitants of builtin types.

Ideally we would emit a reflection info section in libswiftRuntime.o,
but in the meantime just duplicate builtin type metadata for all
builtin types referenced from the current module instead.

In practice only the stdlib and a handful of overlays like the SIMD
overlay use builtin types, and only a few at a time.

Tested manually by running swift-reflection-tool on the standard
library -- I'll add automated tests by using -parse-stdlib to
reference Builtin types in a subsequent patch that adds more layout
logic.

NFC if -enable-reflection-metadata is off.
2016-04-15 00:12:11 -07:00
practicalswift
fa40ad2f0c [gardening] "Objective C" → "Objective-C" 2016-04-09 12:22:18 +02:00
Slava Pestov
8e439904e2 IRGen: Remove special handling of fragile entities in LinkEntity
Dead code now that SILGen enforces this.

This patch was previously committed and reverted; the optimizer
issues exposed by the original version should now be fixed.
2016-04-08 02:46:45 -07:00
David Farler
437d3f2043 Stamp Swift binaries with the reflection version
This will be cross-checked with SwiftRemoteMirror's version
compatibility.

rdar://problem/25559468
2016-04-07 20:16:13 -07:00
Joe Groff
66d5971f42 Merge pull request #2086 from jckarter/generic-objc-subclass
Allow subclasses of specific instantiations of ObjC generic classes.
2016-04-07 08:42:40 -07:00
John McCall
7097facbd4 Fix the code pattern with which we access ObjC classes to correctly
use classrefs instead of accessing the symbol directly.

This might be a very nasty bug to work around.
2016-04-06 21:53:02 -07:00
Joe Groff
9c5564f808 Allow subclasses of specific instantiations of ObjC generic classes.
If a subclass grounds all the type parameters from its base class, we don't have to worry about any erasure edge cases. We should be able to support this, giving existing code that subclasses the nongeneric form of the class a migration path. Spot-fix some places in IRGen where we assume we can't emit static references to ObjC generic classes or metaclasses.
2016-04-06 21:19:11 -07:00
John McCall
52cd8718de Split GenFunc.cpp in three: GenFunc for function types and blocks,
GenCall for function signatures, calls, and prologue/epilogue, and
GenBuiltin for builtin operations.

NFC.
2016-04-04 23:52:14 -07:00
Slava Pestov
3e12eccb56 SIL: Fix miscompiles with @effects(readonly) functions that have indirect results
When resilience is enabled, some functions in the standard library that
are marked @effects(readonly) now have indirect results.

The SILCombiner pass doesn't handle @effects(readonly) with @out results
correctly, so just disable the optimizations temporarily to avoid a
mis-compile when resilience is enabled.

The LLVM readonly attribute can never be applied to such functions, so
don't set it either.

Should not have an effect when resilience is disabled.
2016-04-04 00:05:01 -07:00
Slava Pestov
1872a4ee28 AST: @_versioned types and storage are resilient
Use getEffectiveAccess() instead of getFormalAccess() in a few places.

This should be NFC without -enable-resilience.
2016-04-01 15:30:33 -07:00
Ben Langmuir
021b9c554e Revert "IRGen: Remove special handling of fragile entities in LinkEntity"
This reverts commit 62ad8a6253.
2016-03-29 13:31:16 -07:00
Slava Pestov
62ad8a6253 IRGen: Remove special handling of fragile entities in LinkEntity
Dead code now that SILGen enforces this.
2016-03-28 15:23:29 -07:00
Slava Pestov
49dcef4fb8 IRGen: More accurate LinkEntity::isAvailableExternally() 2016-03-28 13:24:21 -07:00
Joe Groff
92ed4f1a71 IRGen: Erase ObjC generics before forming metadata references.
The generic parameters to an ObjC class don't exist at runtime, so when forming a metadata reference, lower them away.
2016-03-28 09:50:30 -07:00
John McCall
0ffb7278bc Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.

Includes a fix since the earlier commit to make enum metadata
writable if they have an unfilled payload size.  This didn't show
up on Darwin because "constant" is currently unenforced there in
global data containing relocations.

This patch requires an associated LLDB change which is being
submitted in parallel.
2016-03-24 15:10:31 -07:00
John McCall
abba7f0c8b Revert "Only use metadata patterns for generic types; perform other"
This reverts commit 41efb3d4d3.
LLDB has too many tendrils into our metadata.
2016-03-23 20:26:43 -07:00
John McCall
41efb3d4d3 Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.
2016-03-23 17:04:04 -07:00
Adrian Prantl
e1749d245e Don't emit debug info for value witness tables.
Value witness tables have a well-known symbol name, so there is nothing
that the debug info adds on top of it.

On top of that, the DWARF type we previously were emitting them with was
bogus.

rdar://problem/21777112
2016-03-18 16:58:43 -07:00
Mark Lacey
4cd82bff93 Minor cleanup of static initializer emission. 2016-03-15 10:06:44 -07:00
swiftix
2573782c8b Merge pull request #1357 from swiftix/wip-runtime-calling-convention
Prepare the ground for using a new calling convention for functions from the runtime library
2016-03-01 16:22:37 -08:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00