Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the .goto pragma/feature #1363

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/ast/ast_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ const

sfNoForward* = sfRegister ## forward declarations are not required (per module)
sfExperimental* = sfOverriden ## module uses the .experimental switch
sfGoto* = sfOverriden ## var is used for 'goto' code generation
sfWrittenTo* = sfBorrow ## param is assigned to
sfEscapes* = sfProcvar ## param escapes
sfBase* = sfDiscriminant
Expand Down
2 changes: 0 additions & 2 deletions compiler/ast/report_enums.nim
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,7 @@ type
# Codegen
rsemRttiRequestForIncompleteObject
rsemExpectedNimcallProc
rsemDisallowedRangeForComputedGoto
rsemExpectedParameterForJsPattern
rsemExpectedLiteralForGoto
rsemRequiresDeepCopyEnabled
rsemDisallowedOfForPureObjects
rsemCannotCodegenCompiletimeProc
Expand Down
37 changes: 2 additions & 35 deletions compiler/backend/ccgstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,11 @@ proc endBlock(p: BProc) =
blockEnd.addf("}$n", [])
endBlock(p, blockEnd)

proc genGotoVar(p: BProc; value: CgNode) =
case value.kind
of cnkIntLit, cnkUIntLit:
lineF(p, cpsStmts, "goto NIMSTATE_$#;$n", [value.intVal.rope])
else:
localReport(p.config, value.info, reportSem rsemExpectedLiteralForGoto)

proc genBracedInit(p: BProc, n: CgNode; optionalType: PType): Rope

proc genSingleVar(p: BProc, vn, value: CgNode) =
## Generates and emits the C code for the definition statement of a local.
let v = vn.local

if sfGoto in p.body[v].flags:
# translate 'var state {.goto.} = X' into 'goto LX':
genGotoVar(p, value)
return

assignLocalVar(p, vn)
# default-initialize the local if no initial value is supplied. Automatic
# initialization is also ommitted when the `value` expression is a
Expand Down Expand Up @@ -108,20 +95,6 @@ proc genIf(p: BProc, n: CgNode) =
lineF(p, cpsStmts, "if ($1)$n", [rdLoc(a)])
startBlock(p)

proc genGotoForCase(p: BProc; caseStmt: CgNode) =
for i in 1..<caseStmt.len:
startBlock(p)
let it = caseStmt[i]
for j in 0..<it.len-1:
if it[j].kind == cnkRange:
localReport(p.config, it.info, reportSem rsemDisallowedRangeForComputedGoto)
return
let val = getOrdValue(it[j])
lineF(p, cpsStmts, "NIMSTATE_$#:$n", [val.rope])

lineCg(p, cpsStmts, "goto $1;$n", [it[^1].label])
endBlock(p)

proc exit(n: CgNode): CgNode =
# XXX: exists as a convenience for overflow check, index check, etc.
# code gen. Should be removed once those are fully lowered prior
Expand Down Expand Up @@ -284,10 +257,7 @@ proc genOrdinalCase(p: BProc, n: CgNode) =

proc genCase(p: BProc, t: CgNode) =
genLineDir(p, t)
if t[0].kind == cnkLocal and sfGoto in p.body[t[0].local].flags:
genGotoForCase(p, t)
else:
genOrdinalCase(p, t)
genOrdinalCase(p, t)

proc bodyCanRaise(p: BProc; n: CgNode): bool =
case n.kind
Expand Down Expand Up @@ -429,10 +399,7 @@ when false:
expr(p, call, d)

proc genAsgn(p: BProc, e: CgNode) =
if e[0].kind == cnkLocal and sfGoto in p.body[e[0].local].flags:
genLineDir(p, e)
genGotoVar(p, e[1])
else:
if true:
let le = e[0]
let ri = e[1]
var a: TLoc
Expand Down
6 changes: 0 additions & 6 deletions compiler/front/cli_reporter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1993,16 +1993,10 @@ proc reportBody*(conf: ConfigRef, r: SemReport): string =
of rsemRequiresDeepCopyEnabled:
result = "for --gc:arc|orc 'deepcopy' support has to be enabled with --deepcopy:on"

of rsemExpectedLiteralForGoto:
result = "'goto' target must be a literal value"

of rsemExpectedParameterForJsPattern:
result = "wrong importjs pattern; expected parameter at position " &
$r.countMismatch.expected & " but got only: " & $r.countMismatch.got

of rsemDisallowedRangeForComputedGoto:
result = "range notation not available for computed goto"

of rsemExpectedNimcallProc:
result = r.symstr & " needs to have the 'nimcall' calling convention"

Expand Down
6 changes: 1 addition & 5 deletions compiler/sem/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const
wMagic, wHeader, wCompilerProc, wCore, wDynlib,
wNoInit, wCompileTime, wGlobal,
wGensym, wInject,
wGuard, wGoto, wCursor, wNoalias, wAlign}
wGuard, wCursor, wNoalias, wAlign}
constPragmas* = declPragmas + {wHeader, wMagic,
wGensym, wInject,
wIntDefine, wStrDefine, wBoolDefine, wCompilerProc, wCore}
Expand Down Expand Up @@ -1446,10 +1446,6 @@ proc applySymbolPragma(c: PContext, sym: PSym, it: PNode): PNode =
result = sym.guard.ast
else:
result = it
of wGoto:
result = noVal(c, it)
assert sym.kind in {skVar, skLet}
sym.flags.incl sfGoto
of wExportNims:
# XXX: modifying the module graph during application of a symbol
# operator doesn't seem like a good idea...
Expand Down
Loading