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 632 - (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 354 { sourcepath: SrcPath.t,
45 :     group: SrcPath.t * region,
46 : blume 537 sh_spec: Sharing.request }
47 : blume 270 -> info
48 :    
49 : blume 537 val info' : attribs -> GeneralParams.info ->
50 :     { sourcepath: SrcPath.t,
51 :     group: SrcPath.t * region,
52 :     sh_spec: Sharing.request }
53 :     -> info
54 :    
55 : blume 354 val sourcepath : info -> SrcPath.t
56 :     val skelname : info -> string
57 :     val binname : info -> string
58 : blume 632 val group : info -> SrcPath.t
59 : blume 299 val error : GeneralParams.info -> info -> complainer
60 : blume 277
61 : blume 299 val parsetree : GeneralParams.info -> info -> (ast * source) option
62 : blume 301 val exports : GeneralParams.info -> info -> SymbolSet.set option
63 :     val skeleton : GeneralParams.info -> info -> Skeleton.decl option
64 : blume 387 val sh_spec : info -> Sharing.request
65 :     val set_sh_mode : info * Sharing.mode -> unit
66 :     val sh_mode : info -> Sharing.mode
67 : blume 537 val attribs : info -> attribs
68 : blume 301 val lastseen : info -> TStamp.t
69 : blume 279
70 : blume 301 (* forget a parse tree that we are done with *)
71 :     val forgetParsetree : info -> unit
72 :    
73 : blume 487 (* Evict all elements that belong to a given group but which
74 :     * are not of the current generation. "cleanGroup" should be
75 : blume 514 * called right after finishing to parse the group file.
76 :     * If the boolean flag ("nowStable") is set to true, then all
77 :     * members of the group are dismissed regardless of their
78 :     * generation. This is used to get rid of the information for
79 :     * members of now-stable libraries. *)
80 :     val cleanGroup : bool -> SrcPath.t -> unit
81 : blume 301
82 : blume 537 (* See if a given piece of info is (still) known here: *)
83 :     val isKnown : info -> bool
84 :    
85 : blume 487 (* Delete all known info. *)
86 :     val reset : unit -> unit
87 :    
88 : blume 280 (* different ways of describing an sml file using group and source *)
89 :     val spec : info -> string (* sspec *)
90 :     val fullSpec : info -> string (* gspec(sspec) *)
91 : blume 354 val descr : info -> string (* sname *)
92 :     val fullDescr : info -> string (* gname(sspec) *)
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 354 PERS of { group: SrcPath.t * 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 354 INFO of { sourcepath: SrcPath.t,
130 : blume 361 mkSkelname: unit -> string,
131 :     mkBinname: unit -> string,
132 : blume 297 persinfo: persinfo,
133 : blume 387 sh_spec: Sharing.request,
134 : blume 537 attribs: attribs }
135 : blume 270
136 : blume 305 type ord_key = info
137 :    
138 : blume 487 local
139 :     val generation = ref (ref ())
140 :     in
141 :     fun now () = !generation
142 :     fun newGeneration () = generation := ref ()
143 :     end
144 :    
145 : blume 277 fun sourcepath (INFO { sourcepath = sp, ... }) = sp
146 : blume 361 fun skelname (INFO { mkSkelname = msn, ... }) = msn ()
147 :     fun binname (INFO { mkBinname = mbn, ... }) = mbn ()
148 : blume 387 fun sh_spec (INFO { sh_spec = s, ... }) = s
149 : blume 389 fun sh_mode (INFO { persinfo = PERS { sh_mode = ref m, ... }, ... }) = m
150 :     fun set_sh_mode (INFO { persinfo = PERS { sh_mode, ... }, ... }, m) =
151 :     sh_mode := m
152 : blume 537 fun attribs (INFO { attribs = a, ... }) = a
153 : blume 270
154 : blume 299 fun gerror (gp: GeneralParams.info) = GroupReg.error (#groupreg gp)
155 : blume 297
156 :     fun error gp (INFO { persinfo = PERS { group, ... }, ... }) =
157 :     gerror gp group
158 :    
159 : blume 632 fun group (INFO { persinfo = PERS { group = (g, _), ... }, ... }) = g
160 :    
161 : blume 279 fun compare (INFO { sourcepath = p, ... }, INFO { sourcepath = p', ... }) =
162 : blume 354 SrcPath.compare (p, p')
163 : blume 279 fun eq (i, i') = compare (i, i') = EQUAL
164 :    
165 : blume 301 fun lastseen (INFO { persinfo = PERS { lastseen, ... }, ... }) =
166 :     !lastseen
167 :    
168 : blume 354 val knownInfo = ref (SrcPathMap.empty: persinfo SrcPathMap.map)
169 : blume 277
170 : blume 537 fun isKnown (INFO { sourcepath, ... }) =
171 :     isSome (SrcPathMap.find (!knownInfo, sourcepath))
172 :    
173 : blume 365 fun countParseTrees () = let
174 :     fun one (PERS { parsetree = ref (SOME _), ... }, i) = i + 1
175 :     | one (_, i) = i
176 :     in
177 :     SrcPathMap.foldl one 0 (!knownInfo)
178 :     end
179 :    
180 : blume 301 fun forgetParsetree (INFO { persinfo = PERS { parsetree, ... }, ... }) =
181 :     parsetree := NONE
182 :    
183 : blume 514 fun cleanGroup nowStable g = let
184 : blume 487 val n = now ()
185 :     fun isCurrent (PERS { generation = ref gen, group = (g', _), ... }) =
186 : blume 514 ((not nowStable) andalso gen = n)
187 :     orelse SrcPath.compare (g, g') <> EQUAL
188 : blume 301 in
189 : blume 487 knownInfo := SrcPathMap.filter isCurrent (!knownInfo)
190 : blume 301 end
191 :    
192 : blume 487 fun reset () = knownInfo := SrcPathMap.empty
193 :    
194 : blume 330 (* check timestamp and throw away any invalid cache *)
195 :     fun validate (sourcepath, PERS pir) = let
196 :     (* don't use "..." pattern to have the compiler catch later
197 :     * additions to the type! *)
198 : blume 487 val { group, lastseen, parsetree, skeleton, sh_mode, generation } = pir
199 : blume 330 val ts = !lastseen
200 : blume 354 val nts = SrcPath.tstamp sourcepath
201 : blume 330 in
202 : blume 345 if TStamp.needsUpdate { source = nts, target = ts } then
203 : blume 330 (lastseen := nts;
204 : blume 487 generation := now ();
205 : blume 330 parsetree := NONE;
206 :     skeleton := NONE)
207 :     else ()
208 :     end
209 :    
210 : blume 537 fun info' attribs (gp: GeneralParams.info) arg = let
211 :     val { sourcepath, group = gr as (group, region), sh_spec } = arg
212 : blume 310 val policy = #fnpolicy (#param gp)
213 : blume 361 fun mkSkelname () = FNP.mkSkelName policy sourcepath
214 :     fun mkBinname () = FNP.mkBinName policy sourcepath
215 : blume 297 val groupreg = #groupreg gp
216 :     fun newpersinfo () = let
217 : blume 354 val ts = SrcPath.tstamp sourcepath
218 : blume 330 val pi = PERS { group = gr, lastseen = ref ts,
219 : blume 389 parsetree = ref NONE, skeleton = ref NONE,
220 : blume 487 sh_mode = ref (Sharing.SHARE false),
221 :     generation = ref (now ()) }
222 : blume 281 in
223 : blume 354 knownInfo := SrcPathMap.insert (!knownInfo, sourcepath, pi);
224 : blume 297 pi
225 : blume 281 end
226 : blume 297 fun persinfo () =
227 : blume 354 case SrcPathMap.find (!knownInfo, sourcepath) of
228 : blume 297 NONE => newpersinfo ()
229 : blume 487 | SOME (pi as PERS { group = gr' as (g, r), generation, ... }) =>
230 : blume 354 if SrcPath.compare (group, g) <> EQUAL then let
231 :     val n = SrcPath.descr sourcepath
232 : blume 322 in
233 : blume 487 if !generation = now () then
234 : blume 322 (gerror gp gr EM.COMPLAIN
235 :     (concat ["ML source file ", n,
236 :     " appears in more than one group"])
237 :     EM.nullErrorBody;
238 :     gerror gp gr' EM.COMPLAIN
239 :     (concat ["(previous occurence of ", n, ")"])
240 :     EM.nullErrorBody)
241 :     else
242 :     gerror gp gr EM.WARN
243 :     (concat ["ML source file ", n,
244 :     " has switched groups"])
245 :     EM.nullErrorBody;
246 :     newpersinfo ()
247 :     end
248 : blume 330 else (validate (sourcepath, pi); pi)
249 : blume 281 in
250 : blume 297 INFO { sourcepath = sourcepath,
251 : blume 361 mkSkelname = mkSkelname,
252 :     mkBinname = mkBinname,
253 : blume 297 persinfo = persinfo (),
254 : blume 387 sh_spec = sh_spec,
255 : blume 537 attribs = attribs }
256 : blume 281 end
257 : blume 277
258 : blume 592 val info = info' { split = true, extra_compenv = NONE,
259 :     is_rts = false, explicit_core_sym = NONE }
260 : blume 537
261 : blume 275 (* the following functions are only concerned with getting the data,
262 :     * not with checking time stamps *)
263 : blume 297 fun getParseTree gp (i as INFO ir, quiet, noerrors) = let
264 :     val { sourcepath, persinfo = PERS { parsetree, ... }, ... } = ir
265 : blume 281 val err = if noerrors then (fn m => ())
266 : blume 297 else (fn m => error gp i EM.COMPLAIN m EM.nullErrorBody)
267 : blume 274 in
268 : blume 275 case !parsetree of
269 :     SOME pt => SOME pt
270 :     | NONE => let
271 : blume 345 fun work stream = let
272 :     val _ = if noerrors orelse quiet then ()
273 : blume 354 else Say.vsay ["[parsing ",
274 :     SrcPath.descr sourcepath, "]\n"]
275 : blume 345 val source =
276 : blume 492 Source.newSource (SrcPath.osstring' sourcepath,
277 : blume 354 1, stream, false, #errcons gp)
278 : blume 275 in
279 : blume 345 (SF.parse source, source)
280 :     end
281 : blume 364 fun openIt () = TextIO.openIn (SrcPath.osstring sourcepath)
282 : blume 345 val pto =
283 :     SOME (SafeIO.perform { openIt = openIt,
284 :     closeIt = TextIO.closeIn,
285 :     work = work,
286 : blume 459 cleanup = fn _ => () })
287 : blume 365 (* Counting the trees explicitly may be a bit slow,
288 :     * but maintaining an accurate count is difficult, so
289 :     * this method should be robust. (I don't think that
290 :     * the overhead of counting will make a noticeable
291 :     * difference.) *)
292 :     val ntrees = countParseTrees ()
293 : blume 433 val treelimit = #get StdConfig.parse_caching ()
294 : blume 275 in
295 : blume 365 if ntrees < treelimit then
296 :     parsetree := pto
297 :     else ();
298 : blume 275 pto
299 : blume 345 end handle exn as IO.Io _ => (err (General.exnMessage exn); NONE)
300 :     | SF.Compile msg => (err msg; NONE)
301 : blume 274 end
302 :    
303 : blume 297 fun getSkeleton gp (i as INFO ir, noerrors) = let
304 : blume 361 val { sourcepath, mkSkelname, persinfo = PERS pir, ... } = ir
305 : blume 297 val { skeleton, lastseen, ... } = pir
306 : blume 275 in
307 :     case !skeleton of
308 : blume 301 SOME sk => SOME sk
309 : blume 361 | NONE => let
310 :     val skelname = mkSkelname ()
311 :     in
312 :     case SkelIO.read (skelname, !lastseen) of
313 :     SOME sk => (skeleton := SOME sk; SOME sk)
314 :     | NONE =>
315 :     (case getParseTree gp (i, false, noerrors) of
316 :     SOME (tree, source) => let
317 :     fun err sv region s =
318 :     EM.error source region sv s
319 :     EM.nullErrorBody
320 :     val { skeleton = sk, complain } =
321 :     SkelCvt.convert { tree = tree,
322 :     err = err }
323 :     in
324 :     if noerrors then () else complain ();
325 : blume 310 if EM.anyErrors (EM.errors source) then
326 : blume 361 if noerrors then ()
327 :     else error gp i EM.COMPLAIN
328 : blume 310 "error(s) in ML source file"
329 :     EM.nullErrorBody
330 : blume 354 else (SkelIO.write (skelname, sk, !lastseen);
331 : blume 310 skeleton := SOME sk);
332 :     SOME sk
333 : blume 361 end
334 :     | NONE => NONE)
335 :     end
336 : blume 275 end
337 :    
338 : blume 330 fun skeleton0 noerrors gp i = getSkeleton gp (i, noerrors)
339 : blume 281
340 :     (* we only complain at the time of getting the exports *)
341 : blume 301 fun exports gp i = Option.map SkelExports.exports (skeleton0 false gp i)
342 : blume 281 val skeleton = skeleton0 true
343 : blume 275
344 : blume 330 fun parsetree gp i = getParseTree gp (i, true, true)
345 : blume 282
346 : blume 354 fun spec (INFO { sourcepath, ... }) = SrcPath.specOf sourcepath
347 : blume 297 fun fullSpec (INFO { sourcepath, persinfo = PERS { group, ... }, ... }) =
348 : blume 354 concat [SrcPath.specOf (#1 group), "(", SrcPath.specOf sourcepath, ")"]
349 :     fun descr (INFO { sourcepath, ... }) = SrcPath.descr sourcepath
350 :     fun fullDescr (INFO { sourcepath, persinfo = PERS { group, ... }, ... }) =
351 :     concat [SrcPath.descr (#1 group), "(", SrcPath.specOf sourcepath, ")"]
352 : blume 305
353 : blume 306 fun errorLocation (gp: GeneralParams.info) (INFO i) = let
354 :     val { persinfo = PERS { group = (group, reg), ... }, ... } = i
355 : blume 305 in
356 : blume 306 EM.matchErrorString (GroupReg.lookup (#groupreg gp) group) reg
357 : blume 305 end
358 : blume 270 end

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