From 1fb448587c174137b4e66d6b68313f3f1bdf5808 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Fri, 18 Aug 2017 18:06:30 -0700 Subject: [PATCH 1/5] Merge pull request #1796 from wilzbach/fix-17581 Fix Issue 17581 - Document behavior of -betterC --- posix.mak | 2 +- spec/betterc.dd | 59 +++++++++++++++++++++++++++++++++++++++++++++++ spec/footer_gen.d | 2 +- spec/simd.dd | 2 +- spec/spec.dd | 3 ++- spec/spec.ddoc | 3 ++- 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 spec/betterc.dd diff --git a/posix.mak b/posix.mak index afe5f9570c..580376e2da 100644 --- a/posix.mak +++ b/posix.mak @@ -196,7 +196,7 @@ SPEC_ROOT=$(addprefix spec/, \ const3 function operatoroverloading template template-mixin contracts \ version traits errors unittest garbage float iasm ddoc \ interfaceToC cpp_interface objc_interface portability entity memory-safe-d \ - abi simd) + abi simd betterc) SPEC_DD=$(addsuffix .dd,$(SPEC_ROOT)) CHANGELOG_FILES=changelog/${NEXT_VERSION}_pre \ diff --git a/spec/betterc.dd b/spec/betterc.dd new file mode 100644 index 0000000000..653efa37da --- /dev/null +++ b/spec/betterc.dd @@ -0,0 +1,59 @@ +Ddoc + +$(SPEC_S Better C, + +`-betterC` is a command-line flag for `dmd`, +which restricts the compiler's support of certain runtime features. +Notably, D programs or libraries compiled with `betterC` aren't linked with Druntime. +The use of compile-time features is not restricted in any way. + +Limiting a program or library to this subset of runtime features is useful +when targeting constrained environments where the use of such features is not practical or possible. +Additionally, this also makes embedding D libraries in larger projects easier by: + +$(OL + $(LI Simplifying the process of integration at the build-system level) + $(LI Removing the need to ensure that Druntime is properly initialized on calls to the library, when an initialization step is not performed before the library is used.) + $(LI Mixing memory management strategies (GC + manual memory management) can sometimes be tricky, hence removing D's GC from the equation may be a good solution) +) + +--- +extern(C) void main() +{ + import core.stdc.stdio : printf; + printf("Hello betterC\n"); +} +--- + +$(CONSOLE +> dmd -betterC hello.d $(AMP)$(AMP) ./hello +Hello betterC +) + +$(H2 $(LNAME2 consequences, Consequences)) + +As no Druntime is available, many D features won't work. +For example: + +$(OL + $(LI Garbage Collection) + $(LI Thread-local storage) + $(LI TypeInfo and ModuleInfo) + $(LI Classes) + $(LI Built-in threading (e.g. $(MREF core, thread))) + $(LI Dynamic arrays (but not slices) and associative arrays) + $(LI Exceptions) + $(LI `switch` with strings) + $(LI `final switch`) + $(LI `synchronized` and $(MREF core, sync)) + $(LI Static module constructors or deconstructors) + $(LI Struct deconstructors) + $(LI `unittest` (testing can be as usual with the `-betterC` flag)) +) + +$(SPEC_SUBNAV_PREV simd, Vector Extensions) + +) + +Macros: + TITLE=Better C diff --git a/spec/footer_gen.d b/spec/footer_gen.d index fd6955977d..7650aafb4d 100755 --- a/spec/footer_gen.d +++ b/spec/footer_gen.d @@ -49,7 +49,7 @@ void main() navString ~= text("PREV_NEXT ", entries[i - 1].name.stripExtension, ", ", entries[i - 1].title, ", ", entries[i + 1].name.stripExtension, ", ", entries[i + 1].title); else - navString ~= text("PREV_NEXT ", entries[i - 1].name.stripExtension, ", ", entries[i - 1].title); + navString ~= text("PREV ", entries[i - 1].name.stripExtension, ", ", entries[i - 1].title); navString ~= ")"; writefln("%s: %s", entry.name, navString); diff --git a/spec/simd.dd b/spec/simd.dd index 16277a60bd..ff6bd1b52e 100644 --- a/spec/simd.dd +++ b/spec/simd.dd @@ -246,7 +246,7 @@ $(H2 $(LNAME2 x86_64_vec, X86 And X86$(UNDERSCORE)64 Vector Extension Implementa $(H3 $(LNAME2 vector_op_intrinsics, Vector Operation Intrinsics)) $(P See $(CORE_SIMD) for the supported intrinsics.) -$(SPEC_SUBNAV_PREV abi, Application Binary Interface) +$(SPEC_SUBNAV_PREV_NEXT abi, Application Binary Interface, betterc, Better C) ) Macros: diff --git a/spec/spec.dd b/spec/spec.dd index 1c45362e47..666c0d6758 100644 --- a/spec/spec.dd +++ b/spec/spec.dd @@ -48,7 +48,8 @@ $(TOC Table of Contents, $(A entity.html, Named Character Entities), $(A memory-safe-d.html, Memory Safety), $(A abi.html, Application Binary Interface), - $(A simd.html, Vector Extensions) + $(A simd.html, Vector Extensions), + $(A betterc.html, Better C) )) ) diff --git a/spec/spec.ddoc b/spec/spec.ddoc index ab2ba7d6e9..60ca1515d9 100644 --- a/spec/spec.ddoc +++ b/spec/spec.ddoc @@ -77,7 +77,8 @@ $(SUBNAV_TEMPLATE $(ROOT_DIR)spec/entity.html, Named Character Entities, $(ROOT_DIR)spec/memory-safe-d.html, Memory Safety, $(ROOT_DIR)spec/abi.html, Application Binary Interface, - $(ROOT_DIR)spec/simd.html, Vector Extensions + $(ROOT_DIR)spec/simd.html, Vector Extensions, + $(ROOT_DIR)spec/betterc.html, Better C ) ) ) From b835eb37ee54758e7070d0ad109a91d4a271d70e Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Sat, 19 Aug 2017 13:53:43 +0200 Subject: [PATCH 2/5] Merge pull request #1870 from MartinNowak/fix_dlang_org add CHAPTER for spec/betterC --- spec/betterc.dd | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/betterc.dd b/spec/betterc.dd index 653efa37da..b55f4f7684 100644 --- a/spec/betterc.dd +++ b/spec/betterc.dd @@ -56,4 +56,5 @@ $(SPEC_SUBNAV_PREV simd, Vector Extensions) ) Macros: + CHAPTER=40 TITLE=Better C From 920f63efbd1332dd88d3ffc1ae36a6dd82f292b7 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Fri, 1 Sep 2017 14:45:46 +0200 Subject: [PATCH 3/5] update download and changelog for v2.076.0 --- VERSION | 2 +- changelog/2.075.1.dd | 4 +- changelog/{2.076.0_pre.dd => 2.076.0.dd} | 98 +++++++++++++++++++++++- changelog/changelog.ddoc | 2 +- download.dd | 4 +- 5 files changed, 100 insertions(+), 10 deletions(-) rename changelog/{2.076.0_pre.dd => 2.076.0.dd} (85%) diff --git a/VERSION b/VERSION index 385cb28f1e..520c65f173 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.075.1 +2.076.0 diff --git a/changelog/2.075.1.dd b/changelog/2.075.1.dd index 8db7ad5d10..c5e16dee41 100644 --- a/changelog/2.075.1.dd +++ b/changelog/2.075.1.dd @@ -1,6 +1,6 @@ Ddoc -$(CHANGELOG_NAV_LAST 2.075.0) +$(CHANGELOG_NAV 2.075.0,2.076.0) $(VERSION Aug 11, 2017, =================================================, @@ -32,7 +32,7 @@ $(LI $(BUGZILLA 17667): regex$(LPAREN)[r".", r"[\$(LPAREN)\{[\]\}\$(RPAREN)]"]$( $(LI $(BUGZILLA 17668): regex$(LPAREN)q"<[^]>"$(RPAREN)) ) ) -$(CHANGELOG_NAV_LAST 2.075.0) +$(CHANGELOG_NAV 2.075.0,2.076.0) Macros: VER=2.075.1 TITLE=Change Log: $(VER) diff --git a/changelog/2.076.0_pre.dd b/changelog/2.076.0.dd similarity index 85% rename from changelog/2.076.0_pre.dd rename to changelog/2.076.0.dd index ce98e16035..ea27cc900d 100644 --- a/changelog/2.076.0_pre.dd +++ b/changelog/2.076.0.dd @@ -2,11 +2,14 @@ Ddoc $(CHANGELOG_NAV_LAST 2.075.1) -$(VERSION Sep 1, 2017, =================================================, +$(VERSION Sep 01, 2017, =================================================, $(BUGSTITLE Compiler changes, +$(LI $(RELATIVE_LINK2 1_staticforeach,Implement DIP 1010 - $(LINK2 https://github.com/dlang/DIPs/blob/master/DIPs/DIP1010.md, Static foreach))) +$(LI $(RELATIVE_LINK2 2_betterc,$(TT -betterC) enhancements)) $(LI $(RELATIVE_LINK2 avx2,AVX2 was added as $(TT -mcpu=avx2) architecture.)) +$(LI $(RELATIVE_LINK2 betterc,$(TT -betterC) enhancements)) $(LI $(RELATIVE_LINK2 fix17697,Fix Issue 17697 - Ddoc: automatically highlight URLs outside of macro arguments)) $(LI $(RELATIVE_LINK2 staticforeach,Implement DIP 1010 - $(LINK2 https://github.com/dlang/DIPs/blob/master/DIPs/DIP1010.md, Static foreach))) @@ -42,6 +45,78 @@ $(HR) $(BUGSTITLE Compiler changes, +$(LI $(LNAME2 1_staticforeach,Implement DIP 1010 - $(LINK2 https://github.com/dlang/DIPs/blob/master/DIPs/DIP1010.md, Static foreach)) +$(P +Support for `static foreach` has been added. +) + +$(P +`static foreach` is a conditional compilation construct that is to `foreach` what `static if` is to `if`. +It is a convenient way to generate declarations and statements by iteration. +) + +--- +import std.conv: to; + +static foreach(i; 0 .. 10) +{ + + // a `static foreach` body does not introduce a nested scope + // (similar to `static if`). + + // The following mixin declaration is at module scope: + mixin(`enum x` ~ to!string(i) ~ ` = i;`); // declares 10 variables x0, x1, ..., x9 +} + +import std.range: iota; +// all aggregate types that can be iterated with a standard `foreach` +// loop are also supported by static foreach: +static foreach(i; iota(10)) +{ + // we access the declarations generated in the first `static foreach` + pragma(msg, "x", i, ": ", mixin(`x` ~ to!string(i))); + static assert(mixin(`x` ~ to!string(i)) == i); +} + +void main() +{ + import std.conv: text; + import std.typecons: tuple; + import std.algorithm: map; + import std.stdio: writeln; + + // `static foreach` has both declaration and statement forms + // (similar to `static if`). + + static foreach(x; iota(3).map!(i => tuple(text("x", i), i))) + { + // generates three local variables x0, x1 and x2. + mixin(text(`int `,x[0],` = x[1];`)); + + scope(exit) // this is within the scope of `main` + { + writeln(mixin(x[0])); + } + } + + writeln(x0," ",x1," ",x2); // first runtime output +} +--- +) + +$(LI $(LNAME2 2_betterc,$(TT -betterC) enhancements) +$(P +Many improvements were added to the dmd's $(TT -betterC) implementation, most +notably programs compiled with $(TT -betterC) will no longer reference unused +druntime symbols, asserts are implemented as C `` calls, and phobos is +not linked by default. +) + +$(P +See the $(LINK2 $(ROOT_DIR)spec/betterc.html, Better C) specs for more details. +) +) + $(LI $(LNAME2 avx2,AVX2 was added as $(TT -mcpu=avx2) architecture.) $(P This allows the backend to emit AVX2 instructions. The compiler will @@ -50,6 +125,19 @@ AVX2 support is automatically detected with -mcpu=native. ) ) +$(LI $(LNAME2 betterc,$(TT -betterC) enhancements) +$(P +Many improvements were added to the dmd's $(TT -betterC) implementation, most +notably programs compiled with $(TT -betterC) will no longer reference unused +druntime symbols, asserts are implemented as C `` calls, and phobos is +not linked by default. +) + +$(P +See the $(LINK2 $(ROOT_DIR)spec/betterc.html, Better C) specs for more details. +) +) + $(LI $(LNAME2 fix17697,Fix Issue 17697 - Ddoc: automatically highlight URLs outside of macro arguments) $(P URLs which appear in Ddoc text: @@ -113,7 +201,7 @@ static foreach(i; 0 .. 10) // a `static foreach` body does not introduce a nested scope // (similar to `static if`). - + // The following mixin declaration is at module scope: mixin(`enum x` ~ to!string(i) ~ ` = i;`); // declares 10 variables x0, x1, ..., x9 } @@ -137,7 +225,7 @@ void main() // `static foreach` has both declaration and statement forms // (similar to `static if`). - + static foreach(x; iota(3).map!(i => tuple(text("x", i), i))) { // generates three local variables x0, x1 and x2. @@ -148,7 +236,7 @@ void main() writeln(mixin(x[0])); } } - + writeln(x0," ",x1," ",x2); // first runtime output } --- @@ -308,6 +396,7 @@ $(LI $(BUGZILLA 16680): dmd doesn't use druntime optimized versions of subtracti $(LI $(BUGZILLA 17522): win64.mak broken) $(LI $(BUGZILLA 17582): [REG2.059] Applying const to struct declaration should make the struct type const) $(LI $(BUGZILLA 17612): [REG2.063] Segmentation fault with bad object.d) +$(LI $(BUGZILLA 17684): [REG 2.062] `static alias this` bug or incomplete implementation?) $(LI $(BUGZILLA 17690): [REG2.066.0] scope guards leak declarations) $(LI $(BUGZILLA 17695): [Reg 2.076] ICE with vector negation) $(LI $(BUGZILLA 17761): [REG2.075] dmd 2.075.1 creates object files that can't be linked by ld.bfd) @@ -423,6 +512,7 @@ $(LI $(BUGZILLA 17322): Add Magikcraft to organizations using D) $(LI $(BUGZILLA 17480): [Downloads]) $(LI $(BUGZILLA 17524): [The C Preprocessor vs D] "need to worry about"?) $(LI $(BUGZILLA 17560): Enhancement: view and copy full code example for offline compile/play) +$(LI $(BUGZILLA 17581): Document behavior of -betterC) $(LI $(BUGZILLA 17594): Define DDOC_BLANKLINE as an empty HTML paragraph, thus obviating the need to wrap text in $$(LPAREN)P ...$(RPAREN)) ) $(BUGSTITLE Tools bugs, diff --git a/changelog/changelog.ddoc b/changelog/changelog.ddoc index 334f813cf2..32ab36c175 100644 --- a/changelog/changelog.ddoc +++ b/changelog/changelog.ddoc @@ -66,7 +66,7 @@ CHANGELOG_VERSION = $(LI $1$1 ($+)) _=BEGIN_GENERATED_CHANGELOG_VERSIONS CHANGELOG_VERSIONS = - $(CHANGELOG_VERSION_PRE 2.076.0, not yet released) + $(CHANGELOG_VERSION 2.076.0, Sep 01, 2017) $(CHANGELOG_VERSION 2.075.1, Aug 11, 2017) $(CHANGELOG_VERSION 2.075.0, Jul 19, 2017) $(CHANGELOG_VERSION 2.074.1, May 30, 2017) diff --git a/download.dd b/download.dd index ae2a5ca932..4385823580 100644 --- a/download.dd +++ b/download.dd @@ -167,8 +167,8 @@ Macros: DMDV2=$(LATEST) - _=BETA=$(COMMENT $0) - BETA=$0 + BETA=$(COMMENT $0) + _=BETA=$0 B_DMDV2=2.076.0 B_SUFFIX=rc1 From 858edd7d77983e9877d17c81d08fb3d917a8dcf6 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Fri, 1 Sep 2017 15:39:34 +0200 Subject: [PATCH 4/5] fixup slugs picked up from dirty working tree --- changelog/2.076.0.dd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog/2.076.0.dd b/changelog/2.076.0.dd index ea27cc900d..235de6acee 100644 --- a/changelog/2.076.0.dd +++ b/changelog/2.076.0.dd @@ -6,8 +6,8 @@ $(VERSION Sep 01, 2017, =================================================, $(BUGSTITLE Compiler changes, -$(LI $(RELATIVE_LINK2 1_staticforeach,Implement DIP 1010 - $(LINK2 https://github.com/dlang/DIPs/blob/master/DIPs/DIP1010.md, Static foreach))) -$(LI $(RELATIVE_LINK2 2_betterc,$(TT -betterC) enhancements)) +$(LI $(RELATIVE_LINK2 staticforeach,Implement DIP 1010 - $(LINK2 https://github.com/dlang/DIPs/blob/master/DIPs/DIP1010.md, Static foreach))) +$(LI $(RELATIVE_LINK2 betterc,$(TT -betterC) enhancements)) $(LI $(RELATIVE_LINK2 avx2,AVX2 was added as $(TT -mcpu=avx2) architecture.)) $(LI $(RELATIVE_LINK2 betterc,$(TT -betterC) enhancements)) $(LI $(RELATIVE_LINK2 fix17697,Fix Issue 17697 - Ddoc: automatically highlight URLs outside of macro arguments)) @@ -45,7 +45,7 @@ $(HR) $(BUGSTITLE Compiler changes, -$(LI $(LNAME2 1_staticforeach,Implement DIP 1010 - $(LINK2 https://github.com/dlang/DIPs/blob/master/DIPs/DIP1010.md, Static foreach)) +$(LI $(LNAME2 staticforeach,Implement DIP 1010 - $(LINK2 https://github.com/dlang/DIPs/blob/master/DIPs/DIP1010.md, Static foreach)) $(P Support for `static foreach` has been added. ) @@ -104,7 +104,7 @@ void main() --- ) -$(LI $(LNAME2 2_betterc,$(TT -betterC) enhancements) +$(LI $(LNAME2 betterc,$(TT -betterC) enhancements) $(P Many improvements were added to the dmd's $(TT -betterC) implementation, most notably programs compiled with $(TT -betterC) will no longer reference unused From 71d180c64dacff1cf919418e13d5220a0e8c2aa2 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Fri, 1 Sep 2017 15:54:45 +0200 Subject: [PATCH 5/5] fix date format --- changelog/2.076.0.dd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/2.076.0.dd b/changelog/2.076.0.dd index 235de6acee..a657335bd9 100644 --- a/changelog/2.076.0.dd +++ b/changelog/2.076.0.dd @@ -2,7 +2,7 @@ Ddoc $(CHANGELOG_NAV_LAST 2.075.1) -$(VERSION Sep 01, 2017, =================================================, +$(VERSION Sep 1, 2017, =================================================, $(BUGSTITLE Compiler changes,