Skip to content

Commit

Permalink
Add sumtype to Phobos (dlang#7702)
Browse files Browse the repository at this point in the history
Add sumtype to Phobos
merged-on-behalf-of: unknown
  • Loading branch information
pbackus authored Mar 5, 2021
1 parent cb3f5e2 commit 51a70ee
Show file tree
Hide file tree
Showing 9 changed files with 2,558 additions and 7 deletions.
9 changes: 6 additions & 3 deletions .dscanner.ini
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ assert_without_msg="-etc.c.SQL_,\
-std.socket,\
-std.stdio,\
-std.string,\
-std.sumtype,\
-std.traits,\
-std.typecons,\
-std.uni,\
Expand All @@ -211,7 +212,7 @@ assert_without_msg="-etc.c.SQL_,\
; Checks for assignment to auto-ref function parameters
auto_ref_assignment_check="-std.algorithm.mutation,-std.typecons"
; Checks for variables that could be declared immutable
could_be_immutable_check="-std.algorithm.comparison,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.setops,-std.algorithm.sorting,-std.array,-std.base64,-std.bigint,-std.bitmanip,-std.complex,-std.concurrency,-std.container,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.container.util,-std.conv,-std.csv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.stopwatch,-std.datetime.systime,-std.datetime.timezone,-std.digest.crc,-std.digest,-std.digest.hmac,-std.digest.md,-std.digest.murmurhash,-std.digest.ripemd,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.bucketizer,-std.experimental.allocator.building_blocks.fallback_allocator,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.gc_allocator,-std.experimental.allocator.mallocator,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.logger.multilogger,-std.experimental.typecons,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.cstring,-std.internal.digest.sha_SSSE3,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.math.biguintx86,-std.internal.math.errorfunction,-std.internal.math.gammafunction,-std.internal.scopebuffer,-std.internal.test.dummyrange,-std.json,-std.math,-std.mathspecial,-std.meta,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.interfaces,-std.range.primitives,-std.regex,-std.regex.internal.backtracking,-std.regex.internal.generator,-std.regex.internal.ir,-std.regex.internal.kickstart,-std.regex.internal.parser,-std.regex.internal.tests,-std.regex.internal.thompson,-std.signals,-std.socket,-std.stdio,-std.string,-std.traits,-std.typecons,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.windows.registry,-std.xml,-std.zip,-std.zlib"
could_be_immutable_check="-std.algorithm.comparison,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.setops,-std.algorithm.sorting,-std.array,-std.base64,-std.bigint,-std.bitmanip,-std.complex,-std.concurrency,-std.container,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.container.util,-std.conv,-std.csv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.stopwatch,-std.datetime.systime,-std.datetime.timezone,-std.digest.crc,-std.digest,-std.digest.hmac,-std.digest.md,-std.digest.murmurhash,-std.digest.ripemd,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.bucketizer,-std.experimental.allocator.building_blocks.fallback_allocator,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.gc_allocator,-std.experimental.allocator.mallocator,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.logger.multilogger,-std.experimental.typecons,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.cstring,-std.internal.digest.sha_SSSE3,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.math.biguintx86,-std.internal.math.errorfunction,-std.internal.math.gammafunction,-std.internal.scopebuffer,-std.internal.test.dummyrange,-std.json,-std.math,-std.mathspecial,-std.meta,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.interfaces,-std.range.primitives,-std.regex,-std.regex.internal.backtracking,-std.regex.internal.generator,-std.regex.internal.ir,-std.regex.internal.kickstart,-std.regex.internal.parser,-std.regex.internal.tests,-std.regex.internal.thompson,-std.signals,-std.socket,-std.stdio,-std.string,-std.sumtype,-std.traits,-std.typecons,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.windows.registry,-std.xml,-std.zip,-std.zlib"
; Check for poor exception handling practices
exception_check="-std.concurrency,-std.net.curl,-std.parallelism,-std.range,-std.socket,-std.typecons"
; Checks for poor placement of function attributes
Expand Down Expand Up @@ -266,6 +267,7 @@ has_public_example="-etc.c.curl,\
-std.regex.internal.ir,\
-std.socket,\
-std.stdio,\
-std.sumtype,\
-std.uni,\
-std.xml,\
-std.zip,\
Expand All @@ -290,9 +292,9 @@ number_style_check="+disabled"
;number_style_check="-std.algorithm.iteration,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.container.array,-std.conv,-std.datetime.date,-std.datetime.systime,-std.datetime.timezone,-std.digest.crc,-std.digest,-std.digest.md,-std.digest.ripemd,-std.digest.sha,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.checkedint,-std.file,-std.format,-std.functional,-std.internal.math.biguintcore,-std.internal.math.gammafunction,-std.json,-std.math,-std.outbuffer,-std.parallelism,-std.random,-std.range,-std.regex.internal.generator,-std.utf,-std.zip,-std.zlib"
; Checks that opEquals, opCmp, toHash, and toString are either const, immutable
; , or inout.
object_const_check="-std.algorithm.searching,-std.array,-std.bitmanip,-std.concurrency,-std.container.rbtree,-std.conv,-std.datetime.interval,-std.encoding,-std.exception,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.typecons,-std.format,-std.functional,-std.meta,-std.numeric,-std.range,-std.regex,-std.stdio,-std.typecons,-std.variant,-std.xml"
object_const_check="-std.algorithm.searching,-std.array,-std.bitmanip,-std.concurrency,-std.container.rbtree,-std.conv,-std.datetime.interval,-std.encoding,-std.exception,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.typecons,-std.format,-std.functional,-std.meta,-std.numeric,-std.range,-std.regex,-std.stdio,-std.sumtype,-std.typecons,-std.variant,-std.xml"
; Checks that opEquals and toHash are both defined or neither are defined
opequals_tohash_check="-std.complex,-std.container.array,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.datetime,-std.datetime.date,-std.experimental.checkedint,-std.internal.test.dummyrange,-std.json,-std.numeric,-std.random,-std.socket,-std.typecons,-std.uni"
opequals_tohash_check="-std.complex,-std.container.array,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.datetime,-std.datetime.date,-std.experimental.checkedint,-std.internal.test.dummyrange,-std.json,-std.numeric,-std.random,-std.socket,-std.sumtype,-std.typecons,-std.uni"
; Check for properly documented public functions (Returns, Params)
; Note: DScanner doesn't understand documenting parameters of IFTI/eponymous templates.
properly_documented_public_functions="-etc.c.odbc.sql,\
Expand Down Expand Up @@ -383,6 +385,7 @@ properly_documented_public_functions="-etc.c.odbc.sql,\
-std.socket,\
-std.stdio,\
-std.string,\
-std.sumtype,\
-std.typecons,\
-std.uni,\
-std.uri,\
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ std/socket.d @CyberShadow @klickverbot
# std/stdint.d
std/stdio.d @CyberShadow @schveiguy
std/string.d @burner @JackStouffer
std/sumtype.d @pbackus
# std/system.d
std/traits.d @Biotronic @klickverbot @ZombineDev
std/typecons.d @Biotronic @MetaLang @ZombineDev
Expand Down
6 changes: 5 additions & 1 deletion index.d
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,16 @@ $(BOOKTABLE ,
)
$(TR
$(TDNW $(MREF std,variant))
$(TD Discriminated unions and algebraic types.)
$(TD Dynamically-typed variable that can hold a value of any type.)
)
$(TR
$(TDNW $(MREF core,bitop))
$(TD Low level bit manipulation.)
)
$(TR
$(TDNW $(MREF std,sumtype))
$(TD Type-safe discriminated union.)
)
$(LEADINGROW Vector programming)
$(TR
$(TDNW $(MREF core,simd))
Expand Down
23 changes: 22 additions & 1 deletion posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ PACKAGE_std = array ascii base64 bigint bitmanip compiler complex concurrency \
conv csv demangle encoding exception file \
functional getopt json math mathspecial meta mmfile numeric \
outbuffer package parallelism path process random signals socket stdint \
stdio string system traits typecons \
stdio string sumtype system traits typecons \
uri utf uuid variant xml zip zlib
PACKAGE_std_experimental = checkedint typecons
PACKAGE_std_algorithm = comparison iteration mutation package searching setops \
Expand Down Expand Up @@ -670,6 +670,27 @@ betterc: betterc-phobos-tests
--inputdir $< --outputdir $(BETTERCTESTS_DIR)
$(DMD) $(DFLAGS) $(NODEFAULTLIB) -betterC -unittest -run $(BETTERCTESTS_DIR)/$(subst /,_,$<)


################################################################################
# Full-module BetterC tests
# -------------------------
#
# Test full modules with -betterC. Edit BETTERC_MODULES and
# test/betterc_module_tests.d to add new modules to the list.
#
# make -f posix.mak betterc-module-tests
################################################################################

BETTERC_MODULES=std/sumtype

betterc: betterc-module-tests

betterc-module-tests: $(ROOT)/betterctests/betterc_module_tests
$(ROOT)/betterctests/betterc_module_tests

$(ROOT)/betterctests/betterc_module_tests: test/betterc_module_tests.d $(addsuffix .d,$(BETTERC_MODULES))
$(DMD) $(DFLAGS) $(NODEFAULTLIB) -of=$(ROOT)/betterctests/betterc_module_tests -betterC -unittest test/betterc_module_tests.d $(addsuffix .d,$(BETTERC_MODULES))

################################################################################

.PHONY : auto-tester-build
Expand Down
Loading

0 comments on commit 51a70ee

Please sign in to comment.