Commit graph

225 commits

Author SHA1 Message Date
Martin Kinkelin
e9021fd6c8 Refactoring: Improve Ir{Aggr,Class,Struct} encapsulation 2020-10-24 20:07:29 +02:00
Martin Kinkelin
a6ed0e500f Emit struct TypeInfos in referencing CUs only
I.e., not in their owning CU if unused therein, but in all referencing
CUs instead, as linkonce_odr. The special member functions are still
only and unconditionally emitted in the owning CU.
2020-10-11 14:34:49 +02:00
Martin Kinkelin
64aa4fe1e3 Emit struct TypeInfos & special member functions in owning module only
Analogous to ClassInfos, incl. normal linkage (external for non-
templates, weak_odr for templates).

This enables to get rid of frontend logic wrt. whether to add
TypeInfoStructDeclarations to a module's members tree - previously,
it was defined as linkonce_odr in the owning module and each referencing
module (unless speculative) - and related extra semantic and codegen for
the special member functions.
I've gone a bit further and moved the entire TypeInfo emission for LDC
to the codegen layer; no TypeInfoDeclarations are added to the module
members anymore. Whenever we need a TypeInfo symbol during codegen, it
is declared or defined, and we don't need to rely on brittle frontend
logic with speculative-ness complications.

This might slightly increase compilation speed due to less emitted
TypeInfos and functions (possibly less work for the linker too).

A slight drawback is that the job of stripping unused struct TypeInfos
is fully delegated to the linker, as the TypeInfo is guaranteed to end
up in the owning object file due to no linkonce_odr.

Another theoretical drawback is that the optimizer can definitely not
inline xtoHash/xopEquals/xopCmp/xtoString/xdtor[ti]/xpostblit function
pointer indirections in non-owning CUs without LTO (neither the pointers
nor the special member functions are defined anymore).
These (public) members are probably hardly used directly though, and
instead used by the virtual TypeInfo_Struct methods equals/compare/
getHash/destroy/postblit, which are exclusively defined in druntime's
object.o (incl. the TypeInfo_Struct vtable) and aren't cross-module-
inlined anyway (without LTO).

Re-emitting the struct TypeInfos (and optionally the special member
functions too) into each referencing CU could be handled in our codegen
layer, which should be much simpler and more robust than the upstream
scheme.
2020-10-11 12:58:48 +02:00
Martin Kinkelin
e6a2dd852d
Fix issue #3501: Don't re-define struct TypeInfos (#3502)
Surfacing now as #3486 added a corresponding assertion.

I've tested this with an older vibe-d v0.8.6 lying around on my box.
The assertion was hit for the TypeInfo of a nested struct:

3c7ae13989/http/vibe/http/router.d (L570-L574)

I wasn't able to quickly reduce it to a stand-alone testcase and am
reluctant to put any more effort into this.
2020-07-10 23:31:15 +02:00
Martin Kinkelin
c09f7ed617 Revise struct/class/interface TypeInfo generation, incl. getting rid of GENERATE_OFFTI
I've also compared against the current DMD implementations, to make sure
we are in sync.

DMD doesn't populate `TypeInfo_Class.m_offTi` either. This seems like a
leftover of some unimplemented idea (the LDC commit introducing the
CMake option is from 2008); the normal `TypeInfo_Class.interfaces` array
contains the offsets nowadays.
2020-07-04 16:42:52 +02:00
Martin Kinkelin
40dedab1e8 Move TypeInfo_Struct emission to new ir/irstruct.cpp
Incl. getting rid of the dependence on an associated
TypeInfoStructDeclaration, which was only really needed for the mangled
name of the global.

Also slightly revise metadata generation.
2020-07-03 21:52:55 +02:00
Martin Kinkelin
ab619744f2 Refactoring: Specialize IrAggr into IrStruct and IrClass
And move ClassInfo generation from gen/classes.cpp to ir/irclass.cpp.
2020-07-01 21:28:45 +02:00
Martin Kinkelin
967947eb84 Emulate @weak functions on Windows and don't emit COMDATs for ELF anymore
Emulation for @weak global variables is still left out but should be
analogous.

The test adaptations are mostly a revert of 3893840f. The testcase has
shown that @weak hasn't worked properly for ELF (linker apparently
prefers the version in the 1st object file, independent of whether it's
weak or not), because the functions are emitted in COMDATs.
clang emits COMDATs for templates and inline functions only, not for
regular functions.
2020-05-16 20:42:57 +02:00
Martin Kinkelin
67d619e13d Merge upstream stable (dlang/dmd@e37e1be58c) 2020-05-01 23:38:55 +02:00
Martin Kinkelin
70aa3aff7c Upgrade frontend & libs to early v2.092.0 (dlang/dmd@abf2b56326) 2020-04-28 01:37:49 +02:00
Martin Kinkelin
4ac7f0554b Adapt to frontend refactorings 2019-12-22 16:29:45 +01:00
Ivan Butygin
a40c6c7fd2
Make LDC custom passes available to jit, add API for jit compiler options (#2758) 2019-09-08 09:16:05 +03:00
Martin Kinkelin
c1725809c2
-fvisibility=hidden: Hide init symbols, TypeInfos and vtables too if the associated aggregate isn't exported (#3129) 2019-08-20 01:41:26 +02:00
Martin Kinkelin
e52199469f Upgrade front-end & libs to v2.087.0-beta.1 2019-06-21 15:39:45 +02:00
Martin Kinkelin
c17cee71f3 Extend pragma(LDC_no_typeinfo) to classes and interfaces 2019-05-04 20:56:03 +02:00
Martin Kinkelin
314a64c351 Fix pragma(LDC_no_typeinfo) - elide TypeInfo emission for structs 2019-05-04 18:41:51 +02:00
Martin Kinkelin
4a23399236 Aim for consistent #includes (order + dir prefix)
I surely missed a few.
2018-10-20 16:19:46 +02:00
Martin Kinkelin
7776c4081b Upgrade frontend & libs to v2.083.0-beta.1 2018-10-20 16:19:46 +02:00
Martin Kinkelin
7dbd07dd1e Use new extern(D) dtor shims for struct/class TypeInfos
The TypeInfo may need an extern(D) wrapper accounting for ABI
differences wrt. extern(C++) dtor implementations.

This fixes `runnable/cppa.d` for 32-bit x86 targets.
2018-06-23 19:31:43 +02:00
Martin
2dea0e96ee Account for special case of builtin TypeInfos (rt.typeinfo.*)
And aid in debugging by outputting the IR type names if there are type
mismatches when declaring global variables.
2018-04-10 22:13:00 +02:00
Martin
f38a7972a5 Split up getOrCreateGlobal() in {declare,define}Global()
Making it obvious which of the two operations is performed, reducing
call args and making sure a global isn't defined multiple times via
`defineGlobal()`.

The only [intended] functional change is in gen/trycatchfinally.cpp,
where I inserted a check for an existing __cpp_type_info_ptr global when
emitting a catch for C++ exceptions.
2018-04-10 22:13:00 +02:00
Martin
e337cec78a Slightly refactor RTTIBuilder 2018-04-04 19:59:10 +02:00
Martin
24c2d3e867 Skip TypeInfo emission if there's no TypeInfo declaration
This is compatible with DMD.
2018-04-04 19:59:10 +02:00
Martin
bd623f028a Redirect access to remaining TypeInfo subtypes through gen/runtime 2018-04-04 19:59:10 +02:00
Martin
d8f60d2f5c Redirect access to object.d type declarations through gen/runtime
Not all type declarations yet (e.g., some TypeInfo subtypes are still
accessed directly), but those already wrapped as LazyType in the
gen/runtime.cpp module (with check and proper error msg in case object.d
doesn't contain a required declaration).
2018-04-04 19:59:10 +02:00
Martin
df4f854dd5 Upgrade to D v2.079.0-beta.1 2018-02-20 02:04:41 +01:00
Martin
cfad799f48 Merge 2.078.0 front-end and stdlibs 2018-01-06 01:39:18 +01:00
Martin
ad89009d6e Merge 2.077.0 front-end and stdlibs 2017-11-05 18:41:55 +01:00
Martin
3f38f9715a Get rid of special 'typeid(...)' LL types for TypeInfos
Use the real LL type representing the TypeInfo (sub)class directly and
from the beginning, i.e., already for the declaration, instead of
building an extra LL struct type (firstly opaque, then finalized when
defining the TypeInfo via RTTIBuilder).

To get this to work in all cases, the dummy TypeInfo for opaque structs
is now a complete TypeInfo_Struct, with all 11/13 fields zero-
initialized. Previously, it was a special TypeInfo (no extra
TypeInfo_Struct fields) with TypeInfo_Struct vtable, something which DMD
also emits.

Also refactor the RTTIBuilder finalize() interface - e.g., don't set the
linkage there (had to be reverted for ModuleInfos) and only take the
global variable to be defined. Cast the field initializers if required,
e.g., null pointers to appropriately typed function pointers for
TypeInfo_Struct etc.
2017-10-25 00:38:05 +02:00
Martin
3d0a127d96 Skip TypeInfo definitions for -betterC 2017-10-25 00:38:05 +02:00
kinke
d1b30d627c Backport fix for issue #2357 (#2366)
Improve robustness for TypeInfos of speculative types by only eliding
their TypeInfo definition, not the declaration of the LL global
altogether.

`DtoTypeInfoOf()` expects the LL global to be created and otherwise
fails with an assertion or segfault (e.g., issue #2357). So now only
linker errors should result in case the TypeInfo definition is missing.

Also normalize the calls to `DtoTypeInfoOf()` and revise the following
pointer bitcasts, as the LL type of forward-declared TypeInfo globals
may be opaque.
2017-10-18 20:47:09 +02:00
Martin
c251170912 Rename DtoMangled... to getIRMangled... 2017-10-07 14:06:17 +02:00
Martin
c9a3be1295 Let TargetABI fix up LLVM mangles for more special symbols
For ModuleInfos, ModuleRefs, InterfaceInfos, interface vtables & thunks.
2017-10-07 14:06:17 +02:00
Martin
2616261fd2 Revise all LDC-specific errors/warnings/deprecs and insert backticks
For DMD's new syntax highlighting. I grepped in all .{h,cpp} files only.
2017-08-03 22:53:49 +02:00
Martin
1fb269f940 Drop support for LLVM < 3.7 2017-07-16 02:18:00 +02:00
Martin
b0fb08c43a Replace IrGlobal::type by getType()
As it can always be derived from IrGlobal::value, so the 2 fields don't
need to be kept in sync anymore.
2017-06-17 19:48:18 +02:00
Martin
383c2d3a59 Range-ify usages of front-end Arrays 2017-06-04 00:29:44 +02:00
Martin
fd7c075e3b Use DMD's typinf.d directly
Instead of letting our old copy silently go more and more out-of-sync.
In this case, we missed the upstream fix wrt. skipping the declaration of
ClassInfos for speculative class types.

There are 2 noteworthy functional changes for function
`getOrCreateTypeInfoDeclaration()`:

1) The old version always overwrote `torig->vtinfo` with `t->vtinfo` when
   declaring a new TypeInfo, whereas upstream's `genTypeInfo()` only sets
   it if it was null before.

2) The old version called `semanticTypeInfo()` during a semantic pass,
   upstream doesn't.

The LDC-specific exception for class types in `builtinTypeInfo()` is still
required.

Fixes dmd-testsuite's runnable/b16278.d.
2017-03-05 15:06:20 +01:00
Martin
dca21939e1 Merge 2.072.2 front-end
The part needing most attention was ddmd.root.ctfloat, ddmd.target (incl.
gen/target.cpp) and ddmd.builtin. The front-end is now prepared for
elaborate compile-time floating-point types to allow for proper cross-
compilation.

This version still uses the host's `real` type for compile-time reals,
except for MSVC hosts, which still use 64-bit doubles (when compiled with
DMD host compiler too).

Some other changes:

* semantic*() of Statements extracted from statement.d to statementsem.d
* mangle() -> mangleToBuffer()
* Identifier::string -> toChars()
* Token::float80value => floatvalue
* Dsymbol::isAggregateMember() => isMember()
* BoolExp is no more
* ddmd.root.ctfloat: LDC-specific CTFE builtins
2017-01-29 15:48:03 +01:00
Martin
b610dbc0a1 Fix TypeInfo_Struct constants for all non-x86_64 64-bit targets
Fields `m_arg{1,2}` are only declared for x86_64 targets, so there was a
size mismatch. In the best case, this lead to `m_RTInfo` containing a
TypeInfo pointer instead of the `hasPointers` flag in the least
significant bit (=> no `hasPointers`). `hasPointers` is also specified in
`m_flags` though, so I'm not sure `m_RTInfo` is actually used.
2016-12-03 12:21:16 +01:00
Martin
eab29ba173 Only define special member functions if semantic3 was run 2016-08-19 23:22:03 +02:00
Martin
642ca606c3 Run semantic3() before defining special member functions (xopEquals etc.)
This fixes issue #1698.
2016-08-19 22:58:20 +02:00
Martin
40fdf7819a Support non-trivial initializers for enums
E.g., non-zero-initialized structs encountered in issue #1581.
2016-06-26 23:29:10 +02:00
Johan Engelen
1b4b9a07c9 Fix typo: typeinf.h --> typinf.h [NFC] 2016-06-08 10:40:00 +02:00
Johan Engelen
d7ed918766 Fix codegen for static initialization with typeid(A). Resolves issue 1540. 2016-06-08 10:40:00 +02:00
Kai Nacke
763b196a72 Merge remote-tracking branch 'origin/master' into merge-2.070 2016-03-24 22:40:31 +01:00
Kai Nacke
f42273cbe1 Merge branch 'ltsmaster' 2016-03-24 21:50:15 +01:00
Johan Engelen
79d7eb68bc Define TypeInfo symbols as mutable (instead of immutable), to comply with DMD. Fixes issue #1377. 2016-03-23 22:36:08 +01:00
Kai Nacke
88f3de8bea Merge branch 'ltsmaster' 2016-03-22 19:05:07 +01:00
Martin
88dcb4349a Refactor setting linkage type and COMDAT 2016-03-20 16:37:44 +01:00