From fcf65701646cbf6aae15d717489bd3d6b7f8182b Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Fri, 2 Aug 2019 01:39:31 +0200 Subject: [PATCH] Add @betterC to druntime --- .circleci/config.yml | 3 +++ .circleci/run.sh | 7 ++++++ mak/COPY | 1 + mak/WINDOWS | 3 +++ posix.mak | 41 ++++++++++++++++++++++++++++++++++ src/core/atomic.d | 18 ++++++++++----- src/core/internal/attributes.d | 11 +++++++++ 7 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 src/core/internal/attributes.d diff --git a/.circleci/config.yml b/.circleci/config.yml index 2edf398514..b2f6c1afc9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,3 +22,6 @@ jobs: - run: command: ./.circleci/run.sh codecov name: Upload coverage files to CodeCov + - run: + command: ./.circleci/run.sh betterc + name: Run @betterC tests diff --git a/.circleci/run.sh b/.circleci/run.sh index c37d811377..f568158a40 100755 --- a/.circleci/run.sh +++ b/.circleci/run.sh @@ -103,6 +103,12 @@ coverage() { TEST_COVERAGE="1" make -j$N -C . -f posix.mak MODEL=$MODEL unittest-debug } +betterc() +{ + clone https://github.com/dlang/tools.git ../tools master --depth 1 + make -f posix.mak betterc -j$N DUB="$HOME/dlang/dmd-${HOST_DMD_VER}/linux/bin64/dub" +} + codecov() { # CodeCov gets confused by lst files which it can't matched @@ -115,6 +121,7 @@ case $1 in install-deps) install_deps ;; setup-repos) setup_repos ;; style) style ;; + betterc) betterc ;; coverage) coverage ;; codecov) codecov ;; esac diff --git a/mak/COPY b/mak/COPY index b56112f277..1a8342116b 100644 --- a/mak/COPY +++ b/mak/COPY @@ -23,6 +23,7 @@ COPY=\ \ $(IMPDIR)\core\internal\abort.d \ $(IMPDIR)\core\internal\arrayop.d \ + $(IMPDIR)\core\internal\attributes.d \ $(IMPDIR)\core\internal\convert.d \ $(IMPDIR)\core\internal\dassert.d \ $(IMPDIR)\core\internal\hash.d \ diff --git a/mak/WINDOWS b/mak/WINDOWS index 9dc6a29d8f..4cd551976a 100644 --- a/mak/WINDOWS +++ b/mak/WINDOWS @@ -123,6 +123,9 @@ $(IMPDIR)\core\internal\abort.d : src\core\internal\abort.d $(IMPDIR)\core\internal\arrayop.d : src\core\internal\arrayop.d copy $** $@ +$(IMPDIR)\core\internal\attributes.d : src\core\internal\attributes.d + copy $** $@ + $(IMPDIR)\core\internal\convert.d : src\core\internal\convert.d copy $** $@ diff --git a/posix.mak b/posix.mak index a2cb8f626d..6e61403a5a 100644 --- a/posix.mak +++ b/posix.mak @@ -6,6 +6,8 @@ QUIET:= DMD_DIR=../dmd +DUB=dub +TOOLS_DIR=../tools include $(DMD_DIR)/src/osmodel.mak @@ -315,6 +317,9 @@ $(ROOT)/unittest/test_runner: $(UT_DRUNTIME) src/test_runner.d $(DMD) endif +TESTS_EXTRACTOR=$(ROOT)/tests_extractor +BETTERCTESTS_DIR=$(ROOT)/betterctests + # macro that returns the module name given the src path moduleName=$(subst rt.invariant,invariant,$(subst object_,object,$(subst /,.,$(1)))) @@ -385,6 +390,42 @@ clean: $(addsuffix /.clean,$(ADDITIONAL_TESTS)) test/%/.clean: test/%/Makefile $(MAKE) -C test/$* clean +%/.directory : + mkdir -p $* || exists $* + touch $@ + +################################################################################ +# Build the test extractor. +# - extracts and runs public unittest examples to checks for missing imports +# - extracts and runs @betterC unittests +################################################################################ + +$(TESTS_EXTRACTOR): $(TOOLS_DIR)/tests_extractor.d | $(LIB) + $(DUB) build --force --single $< + mv $(TOOLS_DIR)/tests_extractor $@ + +test_extractor: $(TESTS_EXTRACTOR) + +################################################################################ +# Check and run @betterC tests +# ---------------------------- +# +# Extract @betterC tests of a module and run them in -betterC +# +# make -f betterc -j20 # all tests +# make -f posix.mak src/core/memory.betterc # individual module +################################################################################ + +betterc: | $(TESTS_EXTRACTOR) $(BETTERCTESTS_DIR)/.directory + $(MAKE) -f posix.mak $$(find src -type f -name '*.d' | sed 's/[.]d/.betterc/') + +%.betterc: %.d | $(TESTS_EXTRACTOR) $(BETTERCTESTS_DIR)/.directory + @$(TESTS_EXTRACTOR) --betterC --attributes betterC \ + --inputdir $< --outputdir $(BETTERCTESTS_DIR) + @$(DMD) $(NODEFAULTLIB) -betterC $(UDFLAGS) $(UTFLAGS) -od$(BETTERCTESTS_DIR) -run $(BETTERCTESTS_DIR)/$(subst /,_,$<) + +################################################################################ + # Submission to Druntime are required to conform to the DStyle # The tests below automate some, but not all parts of the DStyle guidelines. # See: http://dlang.org/dstyle.html diff --git a/src/core/atomic.d b/src/core/atomic.d index 4cb817a413..33f1f80e71 100644 --- a/src/core/atomic.d +++ b/src/core/atomic.d @@ -10,6 +10,8 @@ module core.atomic; +import core.internal.attributes : betterC; + version (D_InlineAsm_X86) { version = AsmX86; @@ -1471,7 +1473,7 @@ version (unittest) testLoadStore!(MemoryOrder.raw, T)( val ); } - @safe pure nothrow unittest + @betterC @safe pure nothrow unittest { testType!(bool)(); @@ -1483,6 +1485,10 @@ version (unittest) testType!(int)(); testType!(uint)(); + } + + @safe pure nothrow unittest + { testType!(shared int*)(); @@ -1518,7 +1524,7 @@ version (unittest) } } - pure nothrow unittest + @betterC pure nothrow unittest { static if (has128BitCAS) { @@ -1558,7 +1564,7 @@ version (unittest) } } - pure nothrow unittest + @betterC pure nothrow unittest { static struct S { int val; } auto s = shared(S)(1); @@ -1621,7 +1627,7 @@ version (unittest) } // === atomicFetchAdd and atomicFetchSub operations ==== - pure nothrow @nogc @safe unittest + @betterC pure nothrow @nogc @safe unittest { shared ubyte u8 = 1; shared ushort u16 = 2; @@ -1645,7 +1651,7 @@ version (unittest) } } - pure nothrow @nogc @safe unittest + @betterC pure nothrow @nogc @safe unittest { shared ubyte u8 = 1; shared ushort u16 = 2; @@ -1669,7 +1675,7 @@ version (unittest) } } - pure nothrow @nogc @safe unittest // issue 16651 + @betterC pure nothrow @nogc @safe unittest // issue 16651 { shared ulong a = 2; uint b = 1; diff --git a/src/core/internal/attributes.d b/src/core/internal/attributes.d new file mode 100644 index 0000000000..b7253c23e9 --- /dev/null +++ b/src/core/internal/attributes.d @@ -0,0 +1,11 @@ +module core.internal.attributes; + +/** +Used to annotate `unittest`s which need to be tested in a `-betterC` environment. + +Such `unittest`s will be compiled and executed without linking druntime in, with +a `__traits(getUnitTests, mixin(__MODULE__))` style test runner. +Note that just like any other `unittest` in druntime, they will also be compiled +and executed without `-betterC`. +*/ +package(core) enum betterC = 1;