Class: Jade::Frontend::TypeChecking::VarGen

Inherits:
Object
  • Object
show all
Defined in:
lib/jade/frontend/type_checking/var_gen.rb

Overview

Type-var ids must be unique across every scheme that ever flows through unification. Per-instance counters made cross-module imports fragile: a fresh id from one module could equal a quantified id from another, aliasing them through Substitution.apply. A class-level counter makes collisions impossible by construction.

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.counterObject

Returns the value of attribute counter.



14
15
16
# File 'lib/jade/frontend/type_checking/var_gen.rb', line 14

def counter
  @counter
end

Instance Method Details

#fresh(name = nil) ⇒ Object



21
22
23
24
# File 'lib/jade/frontend/type_checking/var_gen.rb', line 21

def fresh(name = nil)
  fresh_id
    .then { Type.var(it, name) }
end

#fresh_idObject



17
18
19
# File 'lib/jade/frontend/type_checking/var_gen.rb', line 17

def fresh_id
  "t#{self.class.counter += 1}"
end

#next(name) ⇒ Object



26
27
28
29
# File 'lib/jade/frontend/type_checking/var_gen.rb', line 26

def next(name)
  "#{name}#{self.class.counter += 1}"
    .then { Type.var(it, name) }
end