Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/cm/smlfile/smlinfo.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/smlfile/smlinfo.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 677 - (view) (download)

1 : blume 275 (*
2 : blume 282 * Bundling information pertaining to one SML source file.
3 :     * - only includes information that does not require running
4 :     * the machine-dependent part of the compiler
5 : blume 275 *
6 :     * (C) 1999 Lucent Technologies, Bell Laboratories
7 :     *
8 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
9 :     *)
10 : blume 270 signature SMLINFO = sig
11 :    
12 :     type info
13 : blume 305 type ord_key = info
14 : blume 270
15 : blume 295 type complainer = GenericVC.ErrorMsg.complainer
16 : blume 297 type ast = GenericVC.Ast.dec
17 :     type region = GenericVC.SourceMap.region
18 : blume 299 type source = GenericVC.Source.inputSource
19 : blume 274
20 : blume 537 type attribs =
21 : blume 592 { split: bool,
22 :     is_rts: bool,
23 :     explicit_core_sym: Symbol.symbol option,
24 : blume 537 extra_compenv: GenericVC.Environment.staticEnv option }
25 :    
26 : blume 279 val eq : info * info -> bool (* compares sourcepaths *)
27 :     val compare : info * info -> order (* compares sourcepaths *)
28 :    
29 : blume 487 (* The idea behind "newGeneration" is the following:
30 :     * Before parsing .cm files (on behalf of CM.make/recomp or CMB.make etc.)
31 :     * we start a new generation. While parsing, when we encounter a new
32 :     * SML source we re-use existing information and bump its generation
33 :     * number to "now". After we are done with one group we can safely
34 :     * evict all info records for files in this group if their generation
35 :     * is not "now".
36 :     * Moreover, if we encounter an entry that has a different owner group,
37 :     * we can either signal an error (if the generation is "now" which means
38 :     * that the file was found in another group during the same parse) or
39 :     * issue a "switched groups" warning (if the generation is older than
40 :     * now which means that the file used to be in another group). *)
41 :     val newGeneration : unit -> unit
42 :    
43 : blume 299 val info : GeneralParams.info ->
44 : blume 666 { sourcepath: SrcPath.file,
45 :     group: SrcPath.file * region,
46 : blume 677 sh_spec: Sharing.request,
47 :     setup: string option * string option }
48 : blume 270 -> info
49 :    
50 : blume 537 val info' : attribs -> GeneralParams.info ->
51 : blume 666 { sourcepath: SrcPath.file,
52 :     group: SrcPath.file * region,
53 : blume 677 sh_spec: Sharing.request,
54 :     setup: string option * string option }
55 : blume 537 -> info
56 :    
57 : blume 666 val sourcepath : info -> SrcPath.file
58 : blume 354 val skelname : info -> string
59 :     val binname : info -> string
60 : blume 666 val group : info -> SrcPath.file
61 : blume 299 val error : GeneralParams.info -> info -> complainer
62 : blume 277
63 : blume 299 val parsetree : GeneralParams.info -> info -> (ast * source) option
64 : blume 301 val exports : GeneralParams.info -> info -> SymbolSet.set option
65 :     val skeleton : GeneralParams.info -> info -> Skeleton.decl option
66 : blume 387 val sh_spec : info -> Sharing.request
67 :     val set_sh_mode : info * Sharing.mode -> unit
68 :     val sh_mode : info -> Sharing.mode
69 : blume 537 val attribs : info -> attribs
70 : blume 301 val lastseen : info -> TStamp.t
71 : blume 677 val setup : info -> string option * string option
72 : blume 279
73 : blume 301 (* forget a parse tree that we are done with *)
74 :     val forgetParsetree : info -> unit
75 :    
76 : blume 487 (* Evict all elements that belong to a given group but which
77 :     * are not of the current generation. "cleanGroup" should be
78 : blume 514 * called right after finishing to parse the group file.
79 :     * If the boolean flag ("nowStable") is set to true, then all
80 :     * members of the group are dismissed regardless of their
81 :     * generation. This is used to get rid of the information for
82 :     * members of now-stable libraries. *)
83 : blume 666 val cleanGroup : bool -> SrcPath.file -> unit
84 : blume 301
85 : blume 537 (* See if a given piece of info is (still) known here: *)
86 :     val isKnown : info -> bool
87 :    
88 : blume 487 (* Delete all known info. *)
89 :     val reset : unit -> unit
90 :    
91 : blume 280 (* different ways of describing an sml file using group and source *)
92 : blume 354 val descr : info -> string (* sname *)
93 : blume 305
94 : blume 306 val errorLocation : GeneralParams.info -> info -> string
95 : blume 270 end
96 :    
97 :     structure SmlInfo :> SMLINFO = struct
98 :    
99 : blume 275 structure Source = GenericVC.Source
100 :     structure SF = GenericVC.SmlFile
101 :     structure EM = GenericVC.ErrorMsg
102 : blume 286 structure FNP = FilenamePolicy
103 : blume 275
104 :     type source = Source.inputSource
105 : blume 297 type ast = GenericVC.Ast.dec
106 :     type region = GenericVC.SourceMap.region
107 : blume 274
108 : blume 295 type complainer = EM.complainer
109 : blume 274
110 : blume 537 type attribs =
111 : blume 592 { split: bool,
112 :     is_rts: bool,
113 :     explicit_core_sym: Symbol.symbol option,
114 : blume 537 extra_compenv: GenericVC.Environment.staticEnv option }
115 :    
116 : blume 487 type generation = unit ref
117 :    
118 : blume 389 (* sh_mode is an elaboration of sh_spec; it must be persistent
119 :     * and gets properly re-computed when there is a new sh_spec *)
120 : blume 297 datatype persinfo =
121 : blume 666 PERS of { group: SrcPath.file * region,
122 : blume 487 generation: generation ref,
123 : blume 297 lastseen: TStamp.t ref,
124 : blume 299 parsetree: (ast * source) option ref,
125 : blume 389 skeleton: Skeleton.decl option ref,
126 :     sh_mode: Sharing.mode ref }
127 : blume 297
128 : blume 275 datatype info =
129 : blume 666 INFO of { sourcepath: SrcPath.file,
130 : blume 361 mkSkelname: unit -> string,
131 :     mkBinname: unit -> string,
132 : blume 297 persinfo: persinfo,
133 : blume 387 sh_spec: Sharing.request,
134 : blume 677 attribs: attribs,
135 :     setup: string option * string option }
136 : blume 270
137 : blume 305 type ord_key = info
138 :    
139 : blume 487 local
140 :     val generation = ref (ref ())
141 :     in
142 :     fun now () = !generation
143 :     fun newGeneration () = generation := ref ()
144 :     end
145 :    
146 : blume 277 fun sourcepath (INFO { sourcepath = sp, ... }) = sp
147 : blume 361 fun skelname (INFO { mkSkelname = msn, ... }) = msn ()
148 :     fun binname (INFO { mkBinname = mbn, ... }) = mbn ()
149 : blume 387 fun sh_spec (INFO { sh_spec = s, ... }) = s
150 : blume 389 fun sh_mode (INFO { persinfo = PERS { sh_mode = ref m, ... }, ... }) = m
151 :     fun set_sh_mode (INFO { persinfo = PERS { sh_mode, ... }, ... }, m) =
152 :     sh_mode := m
153 : blume 537 fun attribs (INFO { attribs = a, ... }) = a
154 : blume 677 fun setup (INFO { setup = s, ... }) = s
155 : blume 270
156 : blume 299 fun gerror (gp: GeneralParams.info) = GroupReg.error (#groupreg gp)
157 : blume 297
158 :     fun error gp (INFO { persinfo = PERS { group, ... }, ... }) =
159 :     gerror gp group
160 :    
161 : blume 632 fun group (INFO { persinfo = PERS { group = (g, _), ... }, ... }) = g
162 :    
163 : blume 279 fun compare (INFO { sourcepath = p, ... }, INFO { sourcepath = p', ... }) =
164 : blume 354 SrcPath.compare (p, p')
165 : blume 279 fun eq (i, i') = compare (i, i') = EQUAL
166 :    
167 : blume 301 fun lastseen (INFO { persinfo = PERS { lastseen, ... }, ... }) =
168 :     !lastseen
169 :    
170 : blume 354 val knownInfo = ref (SrcPathMap.empty: persinfo SrcPathMap.map)
171 : blume 277
172 : blume 537 fun isKnown (INFO { sourcepath, ... }) =
173 :     isSome (SrcPathMap.find (!knownInfo, sourcepath))
174 :    
175 : blume 365 fun countParseTrees () = let
176 :     fun one (PERS { parsetree = ref (SOME _), ... }, i) = i + 1
177 :     | one (_, i) = i
178 :     in
179 :     SrcPathMap.foldl one 0 (!knownInfo)
180 :     end
181 :    
182 : blume 301 fun forgetParsetree (INFO { persinfo = PERS { parsetree, ... }, ... }) =
183 :     parsetree := NONE
184 :    
185 : blume 514 fun cleanGroup nowStable g = let
186 : blume 487 val n = now ()
187 :     fun isCurrent (PERS { generation = ref gen, group = (g', _), ... }) =
188 : blume 514 ((not nowStable) andalso gen = n)
189 :     orelse SrcPath.compare (g, g') <> EQUAL
190 : blume 301 in
191 : blume 487 knownInfo := SrcPathMap.filter isCurrent (!knownInfo)
192 : blume 301 end
193 :    
194 : blume 487 fun reset () = knownInfo := SrcPathMap.empty
195 :    
196 : blume 330 (* check timestamp and throw away any invalid cache *)
197 :     fun validate (sourcepath, PERS pir) = let
198 :     (* don't use "..." pattern to have the compiler catch later
199 :     * additions to the type! *)
200 : blume 487 val { group, lastseen, parsetree, skeleton, sh_mode, generation } = pir
201 : blume 330 val ts = !lastseen
202 : blume 354 val nts = SrcPath.tstamp sourcepath
203 : blume 330 in
204 : blume 345 if TStamp.needsUpdate { source = nts, target = ts } then
205 : blume 330 (lastseen := nts;
206 : blume 487 generation := now ();
207 : blume 330 parsetree := NONE;
208 :     skeleton := NONE)
209 :     else ()
210 :     end
211 :    
212 : blume 537 fun info' attribs (gp: GeneralParams.info) arg = let
213 : blume 677 val { sourcepath, group = gr as (group, region), sh_spec, setup } = arg
214 : blume 310 val policy = #fnpolicy (#param gp)
215 : blume 361 fun mkSkelname () = FNP.mkSkelName policy sourcepath
216 :     fun mkBinname () = FNP.mkBinName policy sourcepath
217 : blume 297 val groupreg = #groupreg gp
218 :     fun newpersinfo () = let
219 : blume 354 val ts = SrcPath.tstamp sourcepath
220 : blume 330 val pi = PERS { group = gr, lastseen = ref ts,
221 : blume 389 parsetree = ref NONE, skeleton = ref NONE,
222 : blume 487 sh_mode = ref (Sharing.SHARE false),
223 :     generation = ref (now ()) }
224 : blume 281 in
225 : blume 354 knownInfo := SrcPathMap.insert (!knownInfo, sourcepath, pi);
226 : blume 297 pi
227 : blume 281 end
228 : blume 297 fun persinfo () =
229 : blume 354 case SrcPathMap.find (!knownInfo, sourcepath) of
230 : blume 297 NONE => newpersinfo ()
231 : blume 487 | SOME (pi as PERS { group = gr' as (g, r), generation, ... }) =>
232 : blume 354 if SrcPath.compare (group, g) <> EQUAL then let
233 :     val n = SrcPath.descr sourcepath
234 : blume 322 in
235 : blume 487 if !generation = now () then
236 : blume 322 (gerror gp gr EM.COMPLAIN
237 :     (concat ["ML source file ", n,
238 :     " appears in more than one group"])
239 :     EM.nullErrorBody;
240 :     gerror gp gr' EM.COMPLAIN
241 :     (concat ["(previous occurence of ", n, ")"])
242 :     EM.nullErrorBody)
243 :     else
244 :     gerror gp gr EM.WARN
245 :     (concat ["ML source file ", n,
246 :     " has switched groups"])
247 :     EM.nullErrorBody;
248 :     newpersinfo ()
249 :     end
250 : blume 330 else (validate (sourcepath, pi); pi)
251 : blume 281 in
252 : blume 297 INFO { sourcepath = sourcepath,
253 : blume 361 mkSkelname = mkSkelname,
254 :     mkBinname = mkBinname,
255 : blume 297 persinfo = persinfo (),
256 : blume 387 sh_spec = sh_spec,
257 : blume 677 attribs = attribs,
258 :     setup = setup }
259 : blume 281 end
260 : blume 277
261 : blume 592 val info = info' { split = true, extra_compenv = NONE,
262 :     is_rts = false, explicit_core_sym = NONE }
263 : blume 537
264 : blume 275 (* the following functions are only concerned with getting the data,
265 :     * not with checking time stamps *)
266 : blume 297 fun getParseTree gp (i as INFO ir, quiet, noerrors) = let
267 :     val { sourcepath, persinfo = PERS { parsetree, ... }, ... } = ir
268 : blume 281 val err = if noerrors then (fn m => ())
269 : blume 297 else (fn m => error gp i EM.COMPLAIN m EM.nullErrorBody)
270 : blume 274 in
271 : blume 275 case !parsetree of
272 :     SOME pt => SOME pt
273 :     | NONE => let
274 : blume 345 fun work stream = let
275 :     val _ = if noerrors orelse quiet then ()
276 : blume 354 else Say.vsay ["[parsing ",
277 :     SrcPath.descr sourcepath, "]\n"]
278 : blume 345 val source =
279 : blume 492 Source.newSource (SrcPath.osstring' sourcepath,
280 : blume 354 1, stream, false, #errcons gp)
281 : blume 275 in
282 : blume 345 (SF.parse source, source)
283 :     end
284 : blume 364 fun openIt () = TextIO.openIn (SrcPath.osstring sourcepath)
285 : blume 345 val pto =
286 :     SOME (SafeIO.perform { openIt = openIt,
287 :     closeIt = TextIO.closeIn,
288 :     work = work,
289 : blume 459 cleanup = fn _ => () })
290 : blume 365 (* Counting the trees explicitly may be a bit slow,
291 :     * but maintaining an accurate count is difficult, so
292 :     * this method should be robust. (I don't think that
293 :     * the overhead of counting will make a noticeable
294 :     * difference.) *)
295 :     val ntrees = countParseTrees ()
296 : blume 433 val treelimit = #get StdConfig.parse_caching ()
297 : blume 275 in
298 : blume 365 if ntrees < treelimit then
299 :     parsetree := pto
300 :     else ();
301 : blume 275 pto
302 : blume 345 end handle exn as IO.Io _ => (err (General.exnMessage exn); NONE)
303 :     | SF.Compile msg => (err msg; NONE)
304 : blume 274 end
305 :    
306 : blume 297 fun getSkeleton gp (i as INFO ir, noerrors) = let
307 : blume 361 val { sourcepath, mkSkelname, persinfo = PERS pir, ... } = ir
308 : blume 297 val { skeleton, lastseen, ... } = pir
309 : blume 275 in
310 :     case !skeleton of
311 : blume 301 SOME sk => SOME sk
312 : blume 361 | NONE => let
313 :     val skelname = mkSkelname ()
314 :     in
315 :     case SkelIO.read (skelname, !lastseen) of
316 :     SOME sk => (skeleton := SOME sk; SOME sk)
317 :     | NONE =>
318 :     (case getParseTree gp (i, false, noerrors) of
319 :     SOME (tree, source) => let
320 :     fun err sv region s =
321 :     EM.error source region sv s
322 :     EM.nullErrorBody
323 :     val { skeleton = sk, complain } =
324 :     SkelCvt.convert { tree = tree,
325 :     err = err }
326 :     in
327 :     if noerrors then () else complain ();
328 : blume 310 if EM.anyErrors (EM.errors source) then
329 : blume 361 if noerrors then ()
330 :     else error gp i EM.COMPLAIN
331 : blume 310 "error(s) in ML source file"
332 :     EM.nullErrorBody
333 : blume 354 else (SkelIO.write (skelname, sk, !lastseen);
334 : blume 310 skeleton := SOME sk);
335 :     SOME sk
336 : blume 361 end
337 :     | NONE => NONE)
338 :     end
339 : blume 275 end
340 :    
341 : blume 330 fun skeleton0 noerrors gp i = getSkeleton gp (i, noerrors)
342 : blume 281
343 :     (* we only complain at the time of getting the exports *)
344 : blume 301 fun exports gp i = Option.map SkelExports.exports (skeleton0 false gp i)
345 : blume 281 val skeleton = skeleton0 true
346 : blume 275
347 : blume 330 fun parsetree gp i = getParseTree gp (i, true, true)
348 : blume 282
349 : blume 354 fun descr (INFO { sourcepath, ... }) = SrcPath.descr sourcepath
350 : blume 305
351 : blume 306 fun errorLocation (gp: GeneralParams.info) (INFO i) = let
352 :     val { persinfo = PERS { group = (group, reg), ... }, ... } = i
353 : blume 305 in
354 : blume 306 EM.matchErrorString (GroupReg.lookup (#groupreg gp) group) reg
355 : blume 305 end
356 : blume 270 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0