Skip to content

Commit

Permalink
Add system types to name collision checking
Browse files Browse the repository at this point in the history
This adds the list of types defined in `system.nim` to the list of
identifiers Futhark will consider as collisions. This means that the
code from #115 will not redefine `u_int` to mean `uint` and break sizes
and alignment, and hopefully avoid similar mistakes in the future.
  • Loading branch information
PMunch committed Aug 2, 2024
1 parent 83e6f34 commit e4ee115
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/futhark.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,23 @@ const
"shl", "shr", "static",
"template", "try", "tuple", "type",
"using",
"var", "void",
"var",
"when", "while",
"xor",
"yield"]
# The following list is generated by running `jq '.entries[] | select (.type == "skType").name'` on the output of `nim jsondoc system.nim`
systemTypes = ["int", "int8", "int16", "int32", "int64", "uint", "uint8",
"uint16", "uint32", "uint64", "float", "float32", "float64", "char",
"string", "cstring", "pointer", "typedesc", "`ptr`", "`ref`", "void",
"auto", "any", "untyped", "typed", "bool", "SomeSignedInt",
"SomeUnsignedInt", "SomeInteger", "SomeFloat", "SomeNumber", "SomeOrdinal",
"`static`", "`type`", "TypeOfMode", "iterable", "Ordinal", "range",
"array", "openArray", "varargs", "seq", "set", "UncheckedArray", "sink",
"lent", "HSlice", "Slice", "byte", "Natural", "Positive", "RootObj",
"RootRef", "RootEffect", "StackTraceEntry", "Exception", "Defect",
"CatchableError", "JsRoot", "owned", "Endianness", "TaintedString",
"csize", "AllocStats", "GC_Strategy", "PFrame", "TFrame", "ForeignCell",
"Channel", "BackwardsIndex", "NimNode", "ForLoopStmt"]
syspaths {.strdefine.} = ""
nodeclguards = defined(nodeclguards)
noopaquetypes = defined(noopaquetypes)
Expand Down Expand Up @@ -204,11 +217,11 @@ proc sanitizeName(usedNames: var HashSet[string], origName: string, kind: string
var
normalizedName = result.nimIdentNormalize()
renamed = false
if usedNames.contains(normalizedName) or result in builtins:
if usedNames.contains(normalizedName) or normalizedName in builtins or normalizedName in systemTypes:
result.add "_" & kind
normalizedName.add kind
renamed = true
if usedNames.contains(normalizedName) or result in builtins:
if usedNames.contains(normalizedName) or normalizedName in builtins or normalizedName in systemTypes:
let uniqueTail = hash(origName).uint32.toHex
result.add "_" & uniqueTail
normalizedName.add uniqueTail
Expand Down Expand Up @@ -294,7 +307,7 @@ proc addEntity(state: var State, name: string, entity: JsonNode) =
state.opaqueTypes.excl name

proc addOpaque(state: var State, opaque: string) =
if not state.entities.hasKey(opaque) and opaque notin builtins:
if not state.entities.hasKey(opaque) and opaque notin builtins and opaque notin systemTypes:
state.opaqueTypes.incl opaque

proc toNimType(json: JsonNode, state: var State): NimNode =
Expand Down

0 comments on commit e4ee115

Please sign in to comment.