Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit f137eca

Browse files
authored
Merge pull request #2715 from wilzbach/betterc
Add @BetterC to druntime
2 parents 1168441 + fcf6570 commit f137eca

7 files changed

Lines changed: 78 additions & 6 deletions

File tree

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ jobs:
2222
- run:
2323
command: ./.circleci/run.sh codecov
2424
name: Upload coverage files to CodeCov
25+
- run:
26+
command: ./.circleci/run.sh betterc
27+
name: Run @betterC tests

.circleci/run.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ coverage() {
103103
TEST_COVERAGE="1" make -j$N -C . -f posix.mak MODEL=$MODEL unittest-debug
104104
}
105105
106+
betterc()
107+
{
108+
clone https://github.com/dlang/tools.git ../tools master --depth 1
109+
make -f posix.mak betterc -j$N DUB="$HOME/dlang/dmd-${HOST_DMD_VER}/linux/bin64/dub"
110+
}
111+
106112
codecov()
107113
{
108114
# CodeCov gets confused by lst files which it can't matched
@@ -115,6 +121,7 @@ case $1 in
115121
install-deps) install_deps ;;
116122
setup-repos) setup_repos ;;
117123
style) style ;;
124+
betterc) betterc ;;
118125
coverage) coverage ;;
119126
codecov) codecov ;;
120127
esac

mak/COPY

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ COPY=\
2323
\
2424
$(IMPDIR)\core\internal\abort.d \
2525
$(IMPDIR)\core\internal\arrayop.d \
26+
$(IMPDIR)\core\internal\attributes.d \
2627
$(IMPDIR)\core\internal\convert.d \
2728
$(IMPDIR)\core\internal\dassert.d \
2829
$(IMPDIR)\core\internal\hash.d \

mak/WINDOWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ $(IMPDIR)\core\internal\abort.d : src\core\internal\abort.d
123123
$(IMPDIR)\core\internal\arrayop.d : src\core\internal\arrayop.d
124124
copy $** $@
125125

126+
$(IMPDIR)\core\internal\attributes.d : src\core\internal\attributes.d
127+
copy $** $@
128+
126129
$(IMPDIR)\core\internal\convert.d : src\core\internal\convert.d
127130
copy $** $@
128131

posix.mak

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
QUIET:=
77

88
DMD_DIR=../dmd
9+
DUB=dub
10+
TOOLS_DIR=../tools
911

1012
include $(DMD_DIR)/src/osmodel.mak
1113

@@ -315,6 +317,9 @@ $(ROOT)/unittest/test_runner: $(UT_DRUNTIME) src/test_runner.d $(DMD)
315317

316318
endif
317319

320+
TESTS_EXTRACTOR=$(ROOT)/tests_extractor
321+
BETTERCTESTS_DIR=$(ROOT)/betterctests
322+
318323
# macro that returns the module name given the src path
319324
moduleName=$(subst rt.invariant,invariant,$(subst object_,object,$(subst /,.,$(1))))
320325

@@ -385,6 +390,42 @@ clean: $(addsuffix /.clean,$(ADDITIONAL_TESTS))
385390
test/%/.clean: test/%/Makefile
386391
$(MAKE) -C test/$* clean
387392

393+
%/.directory :
394+
mkdir -p $* || exists $*
395+
touch $@
396+
397+
################################################################################
398+
# Build the test extractor.
399+
# - extracts and runs public unittest examples to checks for missing imports
400+
# - extracts and runs @betterC unittests
401+
################################################################################
402+
403+
$(TESTS_EXTRACTOR): $(TOOLS_DIR)/tests_extractor.d | $(LIB)
404+
$(DUB) build --force --single $<
405+
mv $(TOOLS_DIR)/tests_extractor $@
406+
407+
test_extractor: $(TESTS_EXTRACTOR)
408+
409+
################################################################################
410+
# Check and run @betterC tests
411+
# ----------------------------
412+
#
413+
# Extract @betterC tests of a module and run them in -betterC
414+
#
415+
# make -f betterc -j20 # all tests
416+
# make -f posix.mak src/core/memory.betterc # individual module
417+
################################################################################
418+
419+
betterc: | $(TESTS_EXTRACTOR) $(BETTERCTESTS_DIR)/.directory
420+
$(MAKE) -f posix.mak $$(find src -type f -name '*.d' | sed 's/[.]d/.betterc/')
421+
422+
%.betterc: %.d | $(TESTS_EXTRACTOR) $(BETTERCTESTS_DIR)/.directory
423+
@$(TESTS_EXTRACTOR) --betterC --attributes betterC \
424+
--inputdir $< --outputdir $(BETTERCTESTS_DIR)
425+
@$(DMD) $(NODEFAULTLIB) -betterC $(UDFLAGS) $(UTFLAGS) -od$(BETTERCTESTS_DIR) -run $(BETTERCTESTS_DIR)/$(subst /,_,$<)
426+
427+
################################################################################
428+
388429
# Submission to Druntime are required to conform to the DStyle
389430
# The tests below automate some, but not all parts of the DStyle guidelines.
390431
# See: http://dlang.org/dstyle.html

src/core/atomic.d

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
module core.atomic;
1212

13+
import core.internal.attributes : betterC;
14+
1315
version (D_InlineAsm_X86)
1416
{
1517
version = AsmX86;
@@ -1471,7 +1473,7 @@ version (unittest)
14711473
testLoadStore!(MemoryOrder.raw, T)( val );
14721474
}
14731475

1474-
@safe pure nothrow unittest
1476+
@betterC @safe pure nothrow unittest
14751477
{
14761478
testType!(bool)();
14771479

@@ -1483,6 +1485,10 @@ version (unittest)
14831485

14841486
testType!(int)();
14851487
testType!(uint)();
1488+
}
1489+
1490+
@safe pure nothrow unittest
1491+
{
14861492

14871493
testType!(shared int*)();
14881494

@@ -1518,7 +1524,7 @@ version (unittest)
15181524
}
15191525
}
15201526

1521-
pure nothrow unittest
1527+
@betterC pure nothrow unittest
15221528
{
15231529
static if (has128BitCAS)
15241530
{
@@ -1558,7 +1564,7 @@ version (unittest)
15581564
}
15591565
}
15601566

1561-
pure nothrow unittest
1567+
@betterC pure nothrow unittest
15621568
{
15631569
static struct S { int val; }
15641570
auto s = shared(S)(1);
@@ -1621,7 +1627,7 @@ version (unittest)
16211627
}
16221628

16231629
// === atomicFetchAdd and atomicFetchSub operations ====
1624-
pure nothrow @nogc @safe unittest
1630+
@betterC pure nothrow @nogc @safe unittest
16251631
{
16261632
shared ubyte u8 = 1;
16271633
shared ushort u16 = 2;
@@ -1645,7 +1651,7 @@ version (unittest)
16451651
}
16461652
}
16471653

1648-
pure nothrow @nogc @safe unittest
1654+
@betterC pure nothrow @nogc @safe unittest
16491655
{
16501656
shared ubyte u8 = 1;
16511657
shared ushort u16 = 2;
@@ -1669,7 +1675,7 @@ version (unittest)
16691675
}
16701676
}
16711677

1672-
pure nothrow @nogc @safe unittest // issue 16651
1678+
@betterC pure nothrow @nogc @safe unittest // issue 16651
16731679
{
16741680
shared ulong a = 2;
16751681
uint b = 1;

src/core/internal/attributes.d

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module core.internal.attributes;
2+
3+
/**
4+
Used to annotate `unittest`s which need to be tested in a `-betterC` environment.
5+
6+
Such `unittest`s will be compiled and executed without linking druntime in, with
7+
a `__traits(getUnitTests, mixin(__MODULE__))` style test runner.
8+
Note that just like any other `unittest` in druntime, they will also be compiled
9+
and executed without `-betterC`.
10+
*/
11+
package(core) enum betterC = 1;

0 commit comments

Comments
 (0)